title: Get domain name
body: <p>My computer is in a Domain (Active Directory) and I need to get the domain name dynamically. I found the following code on the internet:</p>
  
  <pre><code>SelectQuery query = new SelectQuery("Win32_ComputerSystem");
  using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
  {
      foreach (ManagementObject mo in searcher.Get())
      {
          if ((bool)mo["partofdomain"])
          {
              this.Domain = mo["domain"].ToString();
              break;
          }
      }
   }
  </code></pre>
  
  <p>It works exactly as I want and returns exactly the domain name as I want (when I am logged as Administrator). If the user is not a Domain Admin, I have an <code>Access denied</code> exception.</p>
  
  <p>Does anybody know how to get the domain even with non-domain administrator users?</p>
  
  <p>NOTE: I have found this solution on Internet <code>System.Environment.UserDomainName;</code> but it only gives me a part of the domain name.</p>
  
  <p>I.e. my domain is: <code>something.domain.com</code>
  and the <code>UserDomainName</code> returns only <code>something</code>.</p>