R
Roshan
Hi,
I wanted a reliable way of detecting if a given NTAccount object
represents a user account or group account. I was using
SecurityIdentifier.IsAccountSid() method but this doesn't work as I
expected. It returns true for user accounts and also for groups created
by administrator. Right now I am using the WMI class
System.Management.ManagementClass to get a list of all local user
accounts and am iterating over them to see if the given account is a
user account.
System.Management.ManagementClass mc = new
System.Management.ManagementClass("Win32_UserAccount");
System.Management.ManagementObjectCollection objColl =
mc.GetInstances();
foreach (System.Management.ManagementObject obj in objColl)
{
String name = obj.GetPropertyValue("Name") as String;
// Compare name and NTAccount.Value to detect if its a user
}
While this works, it seems unclean and a overtly complex way of doing
things. Does any one know of a clean straight forward way of doing
this?
Thanks,
Roshan
I wanted a reliable way of detecting if a given NTAccount object
represents a user account or group account. I was using
SecurityIdentifier.IsAccountSid() method but this doesn't work as I
expected. It returns true for user accounts and also for groups created
by administrator. Right now I am using the WMI class
System.Management.ManagementClass to get a list of all local user
accounts and am iterating over them to see if the given account is a
user account.
System.Management.ManagementClass mc = new
System.Management.ManagementClass("Win32_UserAccount");
System.Management.ManagementObjectCollection objColl =
mc.GetInstances();
foreach (System.Management.ManagementObject obj in objColl)
{
String name = obj.GetPropertyValue("Name") as String;
// Compare name and NTAccount.Value to detect if its a user
}
While this works, it seems unclean and a overtly complex way of doing
things. Does any one know of a clean straight forward way of doing
this?
Thanks,
Roshan