title: Best way to get the connected network domain name in Windows
body: <p>I would like to find out whether the local Windows system is connected to a network domain (instead of a workgroup) and if so, read the domain's name.</p>
  
  <p>I found these Windows API functions to achieve this:</p>
  
  <pre><code>  GetEnvironmentVariable('USERDNSDOMAIN')
    NetGetJoinInformation
    NetServerGetInfo
    NetWkstaGetInfo
    LookupAccountSid
  </code></pre>
  
  <p>Are there any advantages or disadvantages between them? (faster, more reliable, more accurate, ...)</p>
  
  <p>Which one would you recommend and why?</p>