Click here to Skip to main content
15,905,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I am working on a application in asp.net where I need to get the list of windows users.
Posted

Hello Kedar,

Found the solution:

List users = new List();
var path =
string.Format("WinNT://{0},computer", Environment.MachineName);

using (var computerEntry = new DirectoryEntry(path))
foreach (DirectoryEntry childEntry in computerEntry.Children)
if (childEntry.SchemaClassName == "User")
users.Add(childEntry.Name);

Thanks for your help.
 
Share this answer
 
try below code

C#
DirectoryEntry localMachine = new DirectoryEntry("WinNT://" +
               Environment.MachineName);
DirectoryEntry admGroup = localMachine.Children.Find("administrators",
               "group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members) {
  DirectoryEntry member = new DirectoryEntry(groupMember);
  //...
}
 
Share this answer
 
Comments
rupali4 6-Aug-14 7:30am    
Hi Kedar,

Thanks for quick response.

Code you gave is working.
But then I have 1 more question/ doubt that we have to provide the group name we need to search for users.
But if I need to get all the users irrespective to which group he belongs to, then what parameter will I have to provide to below line
localMachine.Children.Find("administrators", "group");

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