Login | |
|
 |
RE: Enumerate Parent OU and Sub OU - 8/1/2005 10:21:27 AM
|
|
 |
|
| |
ThePariah
Posts: 15
Score: 0
Joined: 6/14/2005
From: United Kingdom
Status: offline
|
Following Lengthy research and posts to newsgroups i have managed to work out how to achieve what i wanted. I post the solution here for the benefit of everyone else. <HTML> <HEAD> <TITLE>Populate Dropdown</TITLE> <HTA:APPLICATION APPLICATION ID="PopulateDropdown" APPLICATIONNAME="PopulateDropdown" BORDER = "thin" CAPTION = "yes" RESIZE = "no" ICON = "sprocket.ico" SHOWINTASKBAR = "yes" SINGLEINSTANCE = "yes" SYSMENU = "yes" WINDOWSTATE = "normal" SCROLL = "yes" SCROLLFLAT = "yes" VERSION = "1.0" INNERBORDER = "no" SELECTION = "no" MAXIMIZEBUTTON = "no" MINIMIZEBUTTON = "yes" NAVIGABLE = "yes" CONTEXTMENU = "yes" BORDERSTYLE = "normal"> </HTA> <style> select { font-family: verdana; font-size: 8pt; width: 300px; margin-left: 0px; } .button { font-family: verdana; font-size: 8pt; } </style> <SCRIPT LANGUAGE="VBScript"> Sub Window_Onload check_button.disabled=True OUSelector.InnerHTML = SelectTargetOU() end Sub Sub EnableCheck() check_button.disabled=False End Sub '----------------------------------------------------------' ' Builds a <SELECT> form with all OUs in canonical format. ' '----------------------------------------------------------' Function SelectTargetOU Const adVarChar = 200 Dim defaultNC, AdConn, AdComm, AdRs, AdRoot, AdQuery Dim SortRs SelectTargetOU = "<SELECT onChange='EnableCheck()' NAME='TargetOU' SIZE='1'><OPTION VALUE=''/>-- Select an Organizational Unit --" defaultNC = GetObject("LDAP://RootDSE").Get("DefaultNamingContext") AdQuery = "SELECT AdsPath, canonicalName " & _ " FROM 'LDAP://" & defaultNC & "'" & _ " WHERE objectCategory='organizationalUnit'" '-----------------------------------------------------------------------' ' Create a disconnected recordset to sort the results because AD can't. ' '-----------------------------------------------------------------------' Set SortRs = CreateObject("ADOR.Recordset") SortRs.fields.append "AdsPath",adVarChar,255 SortRs.fields.append "canonicalName",adVarChar,255 SortRs.open '-------------------------------------------------------------------' ' Create ADOBO connection and command objects and set search options' '-------------------------------------------------------------------' Set AdConn = CreateObject("ADODB.Connection") AdConn.Provider = "ADsDSOObject" AdConn.Open "Active Directory Provider" Set AdComm = CreateObject("ADODB.Command") AdComm.ActiveConnection = AdConn AdComm.Properties("SearchScope") = 2 AdComm.Properties("Page Size") = 500 '---------------------------------------' ' Set query text and execute the query. ' '---------------------------------------' AdComm.CommandText = AdQuery Set AdRs = AdComm.Execute With AdRs While Not .EOF AdsPath = .Fields("AdsPath") canonicalName = .Fields("canonicalName") SortRs.AddNew SortRs.Fields("AdsPath") = AdsPath SortRs.Fields("canonicalName") = canonicalName(0) SortRs.Update .MoveNext Wend End With '------------------------------------------------------------------------------------------' ' Now sort the disconnected record set so it will make sense and build <OPTION> selements. ' '------------------------------------------------------------------------------------------' With SortRs .Sort = "canonicalName asc" .MoveFirst While Not .EOF AdsPath = .Fields("AdsPath") canonicalName = .Fields("canonicalName") SelectTargetOU = SelectTargetOU & "<OPTION VALUE='" & AdsPath & "'/>" & canonicalName & vbCrLf .MoveNext Wend End With SelectTargetOU = SelectTargetOU & "</SELECT>" Set AdConn = Nothing Set AdComm = Nothing Set AdRs = Nothing End Function Sub CheckOU msgbox "You Selected: " & TargetOU.Value End Sub </SCRIPT> </HEAD> <BODY bgcolor="#E5ECF9"> <table> <TD> <SPAN ID='OUSelector'> </SPAN> <input id=checkbutton class="button" type="button" value="Check" name="check_button" onClick="CheckOU"> <input id=quitbutton class="button" type="button" value="Quit" name="quit_button" onClick="Self.Close"> </td> </table> </BODY> </HTML>
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|