Click here to Skip to main content
15,792,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to view list of user in network with programing c#

Share this answer
if (!String.IsNullOrEmpty(domainName))
      DirectoryEntry myDirectoryEntry = new DirectoryEntry(String.Format("LDAP://{0}", domainName));
    DirectorySearcher mySearcher = new DirectorySearcher(myDirectoryEntry);
    SortOption mySort = new SortOption("sn", SortDirection.Ascending);
    mySearcher.Filter = ("(objectCategory=person)");
    mySearcher.Sort = mySort;
      foreach (SearchResult resEnt in mySearcher.FindAll())
          if ( System.Text.RegularExpressions.Regex.IsMatch(resEnt.Properties["displayName"][0].ToString(), "         |admin|test|service|system|[$]", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
           int space = resEnt.Properties["displayName"][0].ToString().IndexOf(" ");
           string formattedName = String.Format("{0}",
           resEnt.Properties["displayName"][0].ToString().Substring(space).PadRight(25), );
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900