How to detect if machine is joined to domain?

后端 未结 12 1989
梦毁少年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:31

    Can also be called by using system.net

    string domain = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName
    

    If the domain string is empty the machine isn't bound.

    Documentation on the property returned https://docs.microsoft.com/en-us/dotnet/api/system.net.networkinformation.ipglobalproperties.domainname?view=netframework-4.7.2#System_Net_NetworkInformation_IPGlobalProperties_DomainName

提交回复
热议问题