如何使用vbscript获取组的SID? [英] How do I get SID for the group using vbscript?

查看:180
本文介绍了如何使用vbscript获取组的SID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过输入组名来获取组的SID,它将返回该SID.有什么办法可以使用vbscript做到这一点?任何帮助都很好

I want to get the SID of a group by input the group name and it will return the SID. Is there any way to do this using vbscript ? Any help would be great

推荐答案

使用WMI解析SID:

Use WMI for resolving the SID:

Set wmi = GetObject("winmgmts://./root/cimv2")

groupname = "..."

qry = "SELECT * FROM Win32_Group WHERE Name='" & groupname & "'"
For Each group In wmi.ExecQuery(qry)
  sid = group.SID
Next

If Not IsEmpty(sid) Then
  WScript.Echo "Group " & groupname & " has SID " & sid & "."
Else
  WScript.Echo "SID For group " & groupname & " could not be resolved."
End If

如果您需要转换AD中使用的二进制SID,建议您执行以下操作:

If you need to convert the binary SIDs used in AD I'd suggest you do something like this:

Function DecodeSID(binSID)
  ReDim octets(LenB(binSID))

  'convert binary string to octet array
  For i = 1 To LenB(binSID)
    octets(i-1) = AscB(MidB(binSID, i, 1))
  Next

  'convert octet array to SID string
  sid = "S-" & CStr(octets(0)) & "-" & Octet2Str(Array(octets(2), octets(3), _
        octets(4), octets(5), octets(6), octets(7)))
  For i = 8 To (4 * octets(1) + 4) Step 4
    sid = sid & "-" & OctetArrayToString(Array(octets(i+3), octets(i+2), _
          octets(i+1), octets(i)))
  Next

  DecodeSID = sid
End Function

Function OctetArrayToString(arr)
  v = 0
  For i = 0 To UBound(arr)
    v = v * 256 + arr(i)
  Next
  OctetArrayToString = CStr(v)
End Function

有关二进制SID的详细信息,请参见此处.

For more information on binary SIDs see here.

这篇关于如何使用vbscript获取组的SID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆