title: How to get a list of all domains?
body: <p>I'm trying to get all domains that are available in the Windows Login dialog (in the Domain dropdown). </p>
  
  <p>I've tried the following code but it only returns the domain I am logged into.  Am I missing something?</p>
  
  <pre><code>StringCollection domainList = new StringCollection();
  try
  {
      DirectoryEntry en = new DirectoryEntry();
      // Search for objectCategory type "Domain"
      DirectorySearcher srch = new DirectorySearcher(en, "objectCategory=Domain");
      SearchResultCollection coll = srch.FindAll();
      // Enumerate over each returned domain.
      foreach (SearchResult rs in coll)
      {
          ResultPropertyCollection resultPropColl = rs.Properties;
          foreach( object domainName in resultPropColl["name"])
          {
              domainList.Add(domainName.ToString());
          }
      }
  }
  catch (Exception ex)
  {
      Trace.Write(ex.Message);
  }
  return domainList;
  </code></pre>