Getting the fully qualified Active Directory domain name (C# / VB.Net)

  • Thread starter Chris Mullins [MVP]
  • Start date
C

Chris Mullins [MVP]

This took me much longer to figure out than it should have, and I couldn't
find anything relevant anywhere, so I figured I would post my solution and
let Google archive it for the ages.

To get the fully qualified AD name ("coversant.com") is not as simple as it
seems. The "Environment.UserDomainName" only returns the old-school name
("COVERSANT").

I looked at several solutions involving System.Directory Services, as well
as some Win32 P/Invoke methods. These would work, but they're ugly, and it
was unclear to me if there are access permissions.

By far the easiest way to get this information turned out to be:
System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName

There's all sorts of other goodies under the NetworkInformation namespace...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top