Retrieving the computer domain namne

This is how to retrieve the full domain name of the current computer:

public static string GetFullComputerName()
  ManagementObject cs;
  using (cs = new ManagementObject("Win32_ComputerSystem.Name='" +
      Environment.MachineName + "'"))
    return String.Format("{0}.{1}", Environment.MachineName, cs["domain"]);

To make this work, you need a reference to System.Management.dll.

The result will be something like:

If anyone has a better approach, please leave a comment 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.