How to detect if machine is joined to domain?

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

    Don't fool with pinvoke if you don't have to.

    Reference System.DirectoryServices, then call:

    System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain()
    

    Throws an ActiveDirectoryObjectNotFoundException if the machine is not domain-joined. The Domain object that's returned contains the Name property you're looking for.

提交回复
热议问题