Hi, Im trying to list all the groups in an OU in a list control (GUICtrlCreateList). The idea is taken from "Hey, Scripting Guy! How Can I List All the Groups in an OU?" And the idea is done in HTA like this: <html>
<head>
<title>List All the Groups in an OU</title>
<HTA:APPLICATION
ID="HTA"
APPLICATIONNAME="ADGroups"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
</head>
<script Language="VBScript">
Sub Window_onload
Set objOU = GetObject("LDAP://ou=Security Groups,ou=Managed Objects,dc=contoso,dc=com")
ObjOU.Filter= Array("Group")
For Each objGroup in objOU
Set objOption = document.createElement("OPTION")
objOption.Text = objGroup.Name
objOption.Value = objGroup.Name
AppsGroups.Add(objOption)
Next
End Sub
</SCRIPT>
<body>
<select size="5" name="AppsGroups"></select>
</body>
</html>So Im trying to do the same with AutoIT. I want to use list control (GUICtrlCreateList) to display the results. I can get the results to a txt file: #include <Array.au3>
Local $colCroups, $sTmp, $Array[1] = ["Group"]
$colGroups = ObjGet("LDAP://ou=Security Groups,ou=Managed Objects,dc=contoso,dc=com")
$colGroups.Filter = $Array
$file = FileOpen("test.txt", 1)
; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
For $objGroup In $colGroups
$sTmp = $objGroup.Name & @CRLF
FileWrite($file, $sTmp)
Next
FileClose($file)or display it in an array (thanks to smashly): #include <Array.au3>
$ListGroups = _ListGroups()
If Not @error Then _ArrayDisplay($ListGroups, "List Groups")
Func _ListGroups()
Local $colCroups, $sTmp, $Array[1] = ["Group"]
$colGroups = ObjGet("LDAP://ou=Security Groups,ou=Managed Objects,dc=contoso,dc=com")
If Not IsObj($colGroups) Then Return SetError(1, 0, 0)
$colGroups.Filter = $Array
For $objGroup In $colGroups
$sTmp &= $objGroup.Name & "|"
Next
Return SetError(0, 0, StringSplit(StringTrimRight($sTmp, 1), "|"))
EndFunc ;==>_ListGroupsbut not in a list control. Can someone help me? Should not that hard, but I just cannot solve this by myself. Here is one of my tests to get it work: #include <Array.au3>
$MainGUI=GUICreate("List AD Groups", 220, 250, 100, 200)
Global $colCroups, $sTmp, $Array[1] = ["Group"]
$colGroups = ObjGet("LDAP://ou=Security Groups,ou=Managed Objects,dc=contoso,dc=com")
$colGroups.Filter = $Array
For $objGroup In $colGroups
$sTmp = $objGroup.Name & "|"
Next
$ListGroups =StringSplit(StringTrimRight($sTmp, 1), "|")
$list = GUICtrlCreateList($ListGroups, 10, 10, 200, 150)
;********************************************************************************
; Display the Main GUI
;********************************************************************************
GUISetState(@SW_SHOW); will display the dialog box
While 1
Sleep(1000); Idle around
WEnd