Retrive User SID via VBScript

Discussion in 'Scripting' started by Richard Moreno, Dec 2, 2003.

  1. I have been trying to create a script to do something very tricky which is
    delete local user profiles from a workstation using a variable for the
    profile name in question. Obviously the correct way from the console is to
    go to the System Properties-User Profiles tab because doing it from the Docs
    & Settings directory still leaves Reg entries.

    So, I can do it manually and know the registry locations to delete the data
    however it's done by the SID of the user account. My problem is how to get
    the user SID for the account. In the 2k Reskit I have the GETSID command
    available however it gives way too much data and calling it from a script
    only runs the command but doesn't give me the output back into my script.

    Does anyone have a method to get the user SID via VBScripting?

    Thanks
    Richard
     
    Richard Moreno, Dec 2, 2003
    #1
    1. Advertisements

  2. Hi

    You can use VBScript/WMI to get the SID of the current user like this:


    WScript.Echo "User SID: " & GetUserSID


    Function GetUserSID()

    Dim sUserSID, oWshNetwork, oUserAccount

    Set oWshNetwork = CreateObject("WScript.Network")
    sUserSID = ""

    On Error Resume Next
    Set oUserAccount=GetObject( _
    "winmgmts://" & oWshNetwork.UserDomain & "/root/cimv2") _
    .Get("Win32_UserAccount.Domain='" & oWshNetwork.ComputerName & "'" _
    & ",Name='" & oWshNetwork.UserName & "'")

    GetUserSID = oUserAccount.SID

    End Function
     
    Torgeir Bakken (MVP), Dec 3, 2003
    #2
    1. Advertisements

  3. Thanks Torgeir-

    I failed to mention this previously however, I need to get the SID of a user
    from another domain. Any ideas? Thanks

    Richard
     
    Richard Moreno, Dec 3, 2003
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.