ChessMaster
June 12th, 2009, 02:02 AM
i am trying to list all windows users on a system using C#. An user with administrator rights will be using the application.
i found very few links for the same using google.
How can i achieve the same? I would also like to access per user appData folder.
boudino
June 12th, 2009, 02:19 AM
All local users, or all users in domain?
ChessMaster
June 12th, 2009, 03:04 AM
will need both on different circumstances
ChessMaster
June 12th, 2009, 05:08 AM
ok some progress finally :)
ArrayList GetSystemUsers()
{
ArrayList users = new ArrayList();
DirectoryEntry root = new DirectoryEntry("WinNT://" + Environment.MachineName);
DirectoryEntry admGroup = root.Children.Find("users", "group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members)
{
DirectoryEntry member = new DirectoryEntry(groupMember);
string str = string.Empty;
users.Add(member.Name);
}
return users;
}
the code gives me what i am after, but not completely. Maybe i havent understood how to use the DirectoryServices.
The above returns users who belong to the users group.
If i need administrators list i need to run that again for administrators, and for guests.
How can i retrieve the whole list in one call?
and....the above call gives me some other values which confuses me.
For administrators, i get.... Domain Admins, & myAdmin. myAdmin is a valid user. Why is Domain Admins returned?
Similarly for users, i get other values along with the user list. (INTERACTIVE, Authenticated Users, ASPNET, Domain Users along with the actual usernames who belong to the user group).
Someway i can just get the list of users?
thanks
ChessMaster
June 14th, 2009, 11:07 PM
anyone??