> Hi;
>
[quoted text clipped - 11 lines]
>
> thanks - dave
Sure, I suppose 'CORP' is the logon domain name of useraccount 'dthielen'.
In this case you to connect to the domain controller and use the
Win32_UserAccount class and you have.
Win32_SystemAccount and Win32_UserAccount are subclasses of Win32_Account.
The former only contains the default local system accounts
(localaccount==true), the second represents the non local accounts
(localaccount == false).
Here's a sample:
public static void Main() {
//Connect to the remote computer
ConnectionOptions co = new ConnectionOptions();
// specify credentials of a valid account with sufficient privileges to
query the root\cimv2 namespace
co.Username = "administrator";
co.Password = "somepasswd";
// Connect to the DC using above credentials
System.Management.ManagementScope ms = new
System.Management.ManagementScope(@"\\DCforCORP\root\cimv2", co);
GetAccountSid("CORP", "administrator", ms);
}
static void GetAccountSid(string domain, string name, ManagementScope ms )
{
string accountSid;
string CIMObject =
String.Format("win32_useraccount.domain='{0}',name='{1}'", domain, name);
Console.WriteLine(CIMObject);
using(ManagementObject mo = new ManagementObject(CIMObject))
{
mo.Scope=ms;
mo.Get();
accountSid = mo["SID"].ToString();
Console.WriteLine(accountSid);
}
}
Willy.
Willy Denoyette [MVP] - 07 Dec 2004 15:24 GMT
>> Hi;
>>
[quoted text clipped - 11 lines]
>>
>> thanks - dave
If you are running in an AD domain, and you are happy with a binary form of
the SID I would suggest you to use System.DirectoryServices classes, like
this:
// Get SID of administrator
using(DirectoryEntry user = new
DirectoryEntry("LDAP://Domain/CN=administrator,cn=users,DC=corp,DC=....,DC=....",
"CORP\\administrator", "hispwd", AuthenticationTypes.Secure))
{
foreach(byte b in user.Properties["objectSid"].Value as byte[])
{
Console.Write(b);
}
}
Willy.