Subscribe to Windows IT Pro
June 11, 2002 12:00 AM

Rem: Mapping a SID to a Username

Windows IT Pro
InstantDoc ID #25287
Rating: (0)
Downloads
25287.zip

How do I map a SID that's stored in the registry to the corresponding username?

You can use the Windows Management Instrumentation (WMI) Scripting Library and the WMI Win32_SID class to map a SID to a username. Listing 2 shows a sample script that maps a SID to the username. The script accepts a single command-line argument, which represents the SID you want to map (e.g., S-1-5-32-544).

The script sets two references—one to the WScript.Arguments collection and one to the WScript.StdOut property. Because it uses StdOut, you must run the script with the cscript.exe host. Next, the script checks the number of command-line arguments; if the number is anything other than 1, the script echoes a brief usage message and exits.

At callout A in Listing 2, the script establishes a connection to WMI, which returns an SWbemServices object. Next, the script uses the SWbemServices Get method to retrieve the instance of the Win32_SID class for the SID that you want to map. The script stores the instance in the variable named wmiSID, which subsequently echoes the properties provided by the Win32_SID class.

To run the sample script, include the target SID after the script name, as in

C:\> Win32_SID.vbs S-1-5-32-544

If a valid SID is passed to the script, your output will look like Figure 1.

To learn more, see the WMI software development kit (SDK) at http://msdn.microsoft.com/library/en-us/wmisdk/wmistart_5kth.asp?frame=true.

Related Content:

ARTICLE TOOLS

Comments
  • Jockel Carter
    10 years ago
    Oct 02, 2002

    So how do I pull the SID information from a machine for the Current User? I need to pull that information and build a registry modification process around it.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.