Code to find out all users in the given Domain

This code uses the LDAP.It first creates a directoryentry to the domain and searches for the users available there.
The search patter is given as (objectClass=User)
You can modify this as * if you need all the objects in that domain.


DirectoryEntry entryToSearch = new DirectoryEntry("LDAP://identitymine");
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entryToSearch);

mySearcher.Filter = ("(objectClass=User)");
foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
DirectoryEntry entry= resEnt.GetDirectoryEntry();
MessageBox.Show(entry.Name);
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: