How to get all user account info in C# (windows VISTA/7).
-
Monday, February 22, 2010 1:50 PMHey guys,
is there a way to get the information (username, home directory, user group, ...) from every user account on a windows machine (VISTA / 7). I'm running the program as an Administrator so rights shouldn't be a problem.
Ofcourse the passwords aren't needed.
Thanks in advance!!!
All Replies
-
Monday, February 22, 2010 3:59 PM
Some info of the user:
MessageBox.Show(Environment.UserDomainName.ToString());
MessageBox.Show(Environment.UserName.ToString());
Also review this link
Si la respuesta te ha sido util Marcala como Respuesta o Votala.
Mi Blog: Jtorrecilla
Enlace a Faq de Winforms en Ingles Muy bueno- Marked As Answer by Harry ZhuModerator Monday, March 01, 2010 2:19 AM
-
Tuesday, February 23, 2010 1:36 AM
Try this (add a reference to System.DirectoryServices.AccountManagement):
PrincipalContext ctx = new PrincipalContext(ContextType.Machine,Environment.MachineName); UserPrincipal user = new UserPrincipal(ctx); user.Name = "*"; PrincipalSearcher ps = new PrincipalSearcher(); ps.QueryFilter = user; PrincipalSearchResult<Principal> result = ps.FindAll(); foreach (Principal p in result) { using (UserPrincipal up = (UserPrincipal)p) { MessageBox.Show(up.Name); } }
Compensating what I don't know yet, with what I do know now.- Proposed As Answer by Stuck on Code Tuesday, February 23, 2010 1:42 AM
- Marked As Answer by Harry ZhuModerator Monday, March 01, 2010 2:19 AM
-
Wednesday, August 04, 2010 1:06 AM
Try this (add a reference to e436f System.DirectoryServices.AccountManagement):
PrincipalContext ctx = new PrincipalContext(ContextType.Machine,Environment.MachineName); UserPrincipal user = new UserPrincipal(ctx); user.Name = "*"; PrincipalSearcher ps = new PrincipalSearcher(); ps.QueryFilter = user; PrincipalSearchResult<Principal> result = ps.FindAll(); foreach (Principal p in result) { using (UserPrincipal up = (UserPrincipal)p) { MessageBox.Show(up.Name); } }
Compensating what I don't know yet, with what I do know now.
Great! I solved the problem with your workaround. Thanks. -
Saturday, April 14, 2012 4:20 AM
For local machine you might want to use
SecurityIdentifier
for Active Directory you might want to see
chanmm

