title: C# accessing active directory with different user credentials
body: <p>There is a new user creation application that we have just provided our users. However these users need the ability to creation users through the application even though they themselves do not have permission to create users.</p>
  
  <p>In C# how do you impersonate another user in order to have this functionality. This application primary using <code>System.DirectoryServices</code>.</p>
  
  <p>Code snippet:</p>
  
  <pre><code>DirectoryEntry dEntry = new DirectoryEntry("LDAP://OU=");
  DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
  //filter just user objects
  dSearcher.SearchScope = SearchScope.Subtree;
  dSearcher.Filter = "(&amp;(objectClass=user)(mail=" + excel_Holding_Table.Rows[i]["EmailAddress"].ToString() + "))";
  dSearcher.PageSize = 1000;
  sResults = dSearcher.FindAll();
  </code></pre>