Win32_UserAccount

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hrvoje Voda

    #1

    Win32_UserAccount

    Does anyone has an example of how to use Win32_UserAccou nt class ?

    I looked in MSDN but there is only a VB example

    Hrcko


  • Willy Denoyette [MVP]

    #2
    Re: Win32_UserAccou nt


    "Hrvoje Voda" <hrvoje.voda@lu atech.com> wrote in message
    news:d71e5p$djo $1@ss405.t-com.hr...[color=blue]
    > Does anyone has an example of how to use Win32_UserAccou nt class ?
    >
    > I looked in MSDN but there is only a VB example
    >
    > Hrcko
    >[/color]

    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.Manageme nt 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_useraccou nt.

    using System;
    using System.Manageme nt;

    public class Application{
    public static void Main()
    {
    // Retrieve the SID of the local "administra tor" account
    string domain = Environment.Mac hineName;
    string sid = GetAccountSid(d omain, "administrator" );
    Console.WriteLi ne(sid);
    }
    static string GetAccountSid(s tring domain, string name)
    {
    string accountSid = null;
    string CIMObject =
    String.Format(" win32_useraccou nt.domain='{0}' ,name='{1}'", domain, name);
    Console.WriteLi ne(CIMObject);
    using(Managemen tObject mo = new ManagementObjec t(CIMObject))
    {
    mo.Get();
    accountSid = mo["SID"].ToString();
    }
    return accountSid;
    }
    }

    Willy.


    Comment

    Working...