Users in local users and groups
-
Hi, I need to obtain the fully list of users and groups in a Server, like you see on Users & Groups, in computer management of control pannel. And the user in the particular group. Any help or idea is greatly appreciated Thanks in advance Surya :confused:
-
Hi, I need to obtain the fully list of users and groups in a Server, like you see on Users & Groups, in computer management of control pannel. And the user in the particular group. Any help or idea is greatly appreciated Thanks in advance Surya :confused:
you can do that using WMI through System.Management namespace (you must add it as reference) you can query
Win32_UserAccount
andWin32_UserGroup
from WMI for collecting your data maybe this is not the best solution but it's going to work :) here is the codepublic class UserManagements
{
public class GroupUser
{
const string PATTERNNAME = ".*Name=\"(?'name'.*)\".*";
const string PATTERNDOMAIN = ".*Domain=\"(?'domain'.*)\",.*";public readonly string groupName; public readonly string partName; public readonly string groupDomain; public readonly string partDomain; public GroupUser(string groupComponent, string partComponent) { this.groupName = Regex.Replace(groupComponent, PATTERNNAME, "${name}"); this.partName = Regex.Replace(partComponent, PATTERNNAME, "${name}"); this.groupDomain = Regex.Replace(groupComponent, PATTERNDOMAIN, "${domain}"); this.partDomain = Regex.Replace(partComponent, PATTERNDOMAIN, "${domain}"); } } public class UserAccount { public readonly int AccountType; public readonly string Caption; public readonly string Description; public readonly bool Disabled; public readonly string Domain; public readonly string FullName; public readonly bool LocalAccount; public readonly bool Lockout; public readonly string Name; public readonly bool PasswordChangeable; public readonly bool PasswordExpires; public readonly bool PasswordRequired; public readonly string SID; public readonly int SIDType; public readonly string Status; public UserAccount(ManagementObject userMO) { this.AccountType = Convert.ToInt32(userMO.Properties\["AccountType"\].Value); this.Caption = userMO.Properties\["Caption"\].Value as string; this.Description = userMO.Properties\["Description"\].Value as string; this.Disabled = Convert.ToBoolean(userMO.Properties\["AccountType"\].Value); this.Domai