Win32_UserAccount

  • Thread starter Thread starter Hrvoje Voda
  • Start date Start date
H

Hrvoje Voda

Does anyone has an example of how to use Win32_UserAccount class ?

I looked in MSDN but there is only a VB example

Hrcko
 
Hrvoje Voda said:
Does anyone has an example of how to use Win32_UserAccount class ?

I looked in MSDN but there is only a VB example

Hrcko

The description and samples in MSDN should be sufficient to use all possible
WMI classes, just make sure you are familiar with the WMI namespace before
you start using the System.Management classes though.
A good way to achieve this is to use the Wbemtest.exe utility that comes
with XP/W2K3 or the WMI studio that comes with the WMI platform SDK.

Anyway, here is a small but complete sample illustrating the use of
win32_useraccount.

using System;
using System.Management;

public class Application{
public static void Main()
{
// Retrieve the SID of the local "administrator" account
string domain = Environment.MachineName;
string sid = GetAccountSid(domain, "administrator");
Console.WriteLine(sid);
}
static string GetAccountSid(string domain, string name)
{
string accountSid = null;
string CIMObject =
String.Format("win32_useraccount.domain='{0}',name='{1}'", domain, name);
Console.WriteLine(CIMObject);
using(ManagementObject mo = new ManagementObject(CIMObject))
{
mo.Get();
accountSid = mo["SID"].ToString();
}
return accountSid;
}
}

Willy.
 
Back
Top