'you have to use other names and credentials from you own environment here!
Set obj = GetObject("LDAP://cn=user_xyz,cn=Users,dc=example,dc=com")
pureSidData = OctetToHexStr(obj.objectSid)
sDDLSidStr = HexStrToSID(pureSidData)
WScript.Echo obj.cn
WScript.Echo pureSidData
WScript.Echo sDDLSidStr
Function HexStrToSID(strSid)
'converts a raw SID hex string to the according SID string (SDDL)
Dim i, data, offset
ReDim data(Len(strSid)/2 - 1)
For i = 0 To UBound(data)
data(i) = CInt("&H" & Mid(strSid, 2*i + 1, 2))
Next
HexStrToSID = "S-" & data(0) & "-" & Byte6ToLong(data(2), data(3), data(4), data(5), data(6), data(7))
blockCount = data(1)
For i = 0 To blockCount - 1
offset = 8 + 4*i
HexStrToSID = HexStrToSID & "-" & Byte4ToLong(data(offset+3), data(offset+2), data(offset+1), data(offset))
Next
End Function
'___________________________________ helper functions
Function OctetToHexStr(var_octet)
'converts pure binary data to a string with the according hexadecimal values
OctetToHexStr = ""
For n = 1 To lenb(var_octet)
OctetToHexStr = OctetToHexStr & Right("0" & hex(ascb(midb(var_octet, n, 1))), 2)
Next
End Function
Function Byte4ToLong(ByVal b1, ByVal b2, ByVal b3, ByVal b4)
'converts 4 bytes to the according lang integer value
Byte4ToLong = b1
Byte4ToLong = Byte4ToLong * 256 + b2
Byte4ToLong = Byte4ToLong * 256 + b3
Byte4ToLong = Byte4ToLong * 256 + b4
End Function
Function Byte6ToLong(ByVal b1, ByVal b2, ByVal b3, ByVal b4, ByVal b5, ByVal b6)
'converts 6 bytes to the according lang integer value
Byte6ToLong = b1
Byte6ToLong = Byte6ToLong * 256 + b2
Byte6ToLong = Byte6ToLong * 256 + b3
Byte6ToLong = Byte6ToLong * 256 + b4
Byte6ToLong = Byte6ToLong * 256 + b5
Byte6ToLong = Byte6ToLong * 256 + b6
End Function
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)