title: How to get users from Active Directory in C# and display them in a ComboBox
body: <p>I'm trying to show, in a <code>ComboBox</code> control, the users from an Active Directory on the network. To do this, I've the next function:</p>
  
  <pre><code>public static List&lt;Usuario&gt; MostrarUsuariosDominio()
      {
          List&lt;Usuario&gt; rst = new List&lt;Usuario&gt;();
  
          try
          {
  
              DirectoryContext dc = new DirectoryContext(DirectoryContextType.Domain, Environment.UserDomainName);
              Domain domain = Domain.GetDomain(dc);
              DirectoryEntry de = domain.GetDirectoryEntry();
  
              DirectorySearcher adSearcher = new DirectorySearcher(de); 
  
              adSearcher.Filter = "(&amp;(objectClass=user)(objectCategory=person))";
              adSearcher.PropertiesToLoad.Add("samaccountname");
  
              SearchResult result;
              SearchResultCollection iResult = adSearcher.FindAll();
  
              Usuario item;
              if (iResult != null)
              {
                  for (int counter = 0; counter &lt; iResult.Count; counter++)
                  {
                      result = iResult[counter];
                      if (result.Properties.Contains("samaccountname"))
                      {
                          item = new Usuario();
  
                          item.Nombre = (String)result.Properties["samaccountname"][0];
  
                          rst.Add(item);
                      }
                  }
              }
  
              adSearcher.Dispose();
          }
  
          catch (Exception ex)
          {
              Usuario item = new Usuario();
              item.Nombre = "No se pudo recuperar la lista de usuarios";
              rst.Add(item);
          }
  
          return rst;
      }
  </code></pre>
  
  <p>If I run the application in the PC who's domain controller it works fine: the function returns to me all users. But if I run it on another PC, I get the exception:</p>
  
  <blockquote>
    <p>Specified domain does not exist or couldn't contact with it</p>
  </blockquote>
  
  <p>Is there any way to recover the users list from another PC?</p>