How to detect if machine is joined to domain?

后端 未结 12 1952
梦毁少年i
梦毁少年i 2020-11-28 08:59

How do I detect whether the machine is joined to an Active Directory domain (versus in Workgroup mode)?

12条回答
  •  死守一世寂寞
    2020-11-28 09:45

    The Environment variables could work for you.

    Environment.UserDomainName
    

    MSDN Link for some more details.

    Environment.GetEnvironmentVariable("USERDNSDOMAIN")
    

    I'm not sure this environment variable exists without being in a domain.

    Correct me if I'm wrong Windows Admin geeks -- I believe a computer can be in several domains so it may be more important to know what domain, if any, you are in instead of it being in any domain.

提交回复
热议问题