Forum Search:
Forum.Brain-Cluster.com: Brain Cluster Technical Forum
Ultimate forum for Technical Discussions

Home » Microsoft » Windows Server » Active Directory » Can not use javascript operate AD objectSid.
Can not use javascript operate AD objectSid. [message #161439] Sun, 27 September 2009 01:36
liyong  is currently offline liyong  China
Messages: 23
Registered: July 2009
Junior Member
I have a script to get AD's object sid, I can using vbscript do it, but I
must use java script in product Env. Now
the java script has error, anyone can help me?
my issue is I cannot operate the field 'objectSid' in javascript.
I have post both VBscript code and javascript ( javascript is only a little,
which include the error)

//javascript code for test, the code must run under a domain context, that
means you must login to a domain before you test
var ObjRootDSE=GetObject("LDAP://rootDSE");
var strDomain = ObjRootDSE.Get("defaultNamingContext");
alert(strDomain);
var rootGroups=GetObject("LDAP://" + strDomain);
var enumRoot = new Enumerator( rootGroups);
for (;!enumRoot .atEnd();enumRoot.moveNext())
{
var rootItem=enumRoot.item();
var x=rootItem.objectSid; //or rootItem.objectsid; have the same error
rootItem.Name; //ok
x==null; // false; not null
//x+""; // error,
//rootItem.objectSid.valueOf(); // error, rootItem.objectsid.valueOf()
also error
//x.length; // error ?
}



' VB script////////////////////////////////////////////////
sub GetLDAP()
Set ObjRootDSE = GetObject("LDAP://rootDSE")
strDomain = ObjRootDSE.Get("defaultNamingContext")
Set groups = GetObject("LDAP://" & strDomain)
For Each GroupItem In groups
Debug.Print GroupItem.Name & ", SID=" &
Module1.HexStrToDecStr(Module1.OctetToHexStr(GroupItem.objec tsid))
Set childgroups = GetObject("LDAP://" & GroupItem.Name & "," &
strDomain)
For Each childgroupItem In childgroups
'Debug.Print vbTab & childgroupItem.Name & ", SID=" &
Module1.OctetToHexStr(childgroupItem.objectsid)
'Debug.Print vbTab & childgroupItem.Name & ", SID=" &
Module1.HexStrToDecStr(Module1.OctetToHexStr(childgroupItem. objectsid))
Next
Next
End sub
'''''''''''''''''''''''''''''''''
Function OctetToHexStr(arrbytOctet)
' Function to convert OctetString (byte array) to Hex string.

Dim k
OctetToHexStr = ""
For k = 1 To LenB(arrbytOctet)
OctetToHexStr = OctetToHexStr & Right("0" & Hex(AscB(MidB(arrbytOctet, k,
1))), 2)
Next
End Function
''''''''''''''''''''''''''''''''''''''''
Function HexStrToDecStr(strSid)
' Function to convert hex Sid to decimal (SDDL) Sid.
If strSid = "" Then Exit Function
Dim arrbytSid, lngTemp, j

ReDim arrbytSid(Len(strSid) / 2 - 1)
For j = 0 To UBound(arrbytSid)
arrbytSid(j) = CInt("&H" & Mid(strSid, 2 * j + 1, 2))
Next

HexStrToDecStr = "S-" & arrbytSid(0) & "-" _
& arrbytSid(1) & "-" & arrbytSid(8)
If UBound(arrbytSid) >= 15 Then

lngTemp = arrbytSid(15)
lngTemp = lngTemp * 256 + arrbytSid(14)
lngTemp = lngTemp * 256 + arrbytSid(13)
lngTemp = lngTemp * 256 + arrbytSid(12)

HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
End If
If UBound(arrbytSid) >= 19 Then
lngTemp = arrbytSid(19)
lngTemp = lngTemp * 256 + arrbytSid(18)
lngTemp = lngTemp * 256 + arrbytSid(17)
lngTemp = lngTemp * 256 + arrbytSid(16)

HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
End If
If UBound(arrbytSid) >= 23 Then
lngTemp = arrbytSid(23)
lngTemp = lngTemp * 256 + arrbytSid(22)
lngTemp = lngTemp * 256 + arrbytSid(21)
lngTemp = lngTemp * 256 + arrbytSid(20)

HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
End If
If UBound(arrbytSid) >= 25 Then
lngTemp = arrbytSid(25)
lngTemp = lngTemp * 256 + arrbytSid(24)

HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp)
End If
End Function
Previous Topic:Built in vs Users container
Next Topic:new DC in other site
Goto Forum:
  


Current Time: Wed Jan 17 05:38:14 MST 2018

Total time taken to generate the page: 0.02871 seconds
.:: Contact :: Home ::Sitemap::.

Powered by: FUDforum 3.0.0RC2.
Copyright ©2001-2009 FUDforum Bulletin Board Software