Machine's domain name in .NET?

前端 未结 6 1004
小蘑菇
小蘑菇 2021-02-03 22:47

There gotta be an easy way to do this, I can\'t believe there\'s none. I have scanned through net and found, like, 20 different methods to find in which domain current user is,

6条回答
  •  野的像风
    2021-02-03 23:12

    System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain() wraps DsGetDcName which will search the network for a domain controller even if the machine is not part of a domain. (see remarks)

    As alternative to NetGetJoinInformation you could use GetComputerNameEx with the COMPUTER_NAME_FORMAT.ComputerNameDnsDomain flag to get the full DNS domain name.

    (If not part of a domain, it still returns true, but the resulting string will be empty.)

提交回复
热议问题