Search code examples
c#vbscriptconverterssid

Convert String to SID without Win32-Query


There is a way to convert the SID into a human readable string, there are many useful posts on stack. But is there also a way in the other direction? To convert a string into an SID?

The background is I want to add DCOM user, but the rule is written in SDDL-syntax. I understood the SDDL-syntax for the rights, but I wasn't able to find a way to convert my string "group" in an SID 3-445-33445-34 (for example).

Is there maybe a function in VBScript or something else?
I have seen this question but the solution is not working for me.


Solution

  • Found the solution:

    strComputer = "."
    strGroup = "GroupName"
    strDomain = "DomainName"
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set objAccount = objWMIService.Get("Win32_Group.Name='" & strGroup &"',Domain='"& strDomain &"'")
    MSGBOX objAccount.SID