Jump to content

Recommended Posts

Posted

Iceman682,

no problem to discuss two subjects at the same time - this is the help and support thread ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Shouldn't you set variable $newTOU because that's the variable you then pass to _AD_GetOUTreeView?

If BitAND(GUICtrlRead($USARadio), $GUI_CHECKED) Then

$newTOU = ("OU=USA,DC=Domain,DC=com")

EndIf

If BitAND(GUICtrlRead($AfricaRadio), $GUI_CHECKED) Then

$newTOU = ("OU=Africa,DC=Domain,DC=com")

EndIf

Local $aTreeView = _AD_GetOUTreeView($newOU, $hTree)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Many thanks Water, Sorry, I don't follow?

Aren't I setting the variable to $newTOU by inserting

Local $newOU = $newTOU

Or do I need to change $newOU below to $newTOU

Local $aTreeView = _AD_GetOUTreeView($newOU, $hTree)

Edited by Iceman682
Posted

From the code you have provided I can't decide which of the two ways to select.

You need to make sure that the string the user selected is passed to _AD_GetOUTreeView.

You could test both and see which one works for you.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • 2 weeks later...
Posted

I'm trying to use _AD_MoveObject , but I have no idea what you mean by FQDN for the OU. I've dried the Canonical Name: domain.invalid/Test/OU as well as the Distinguished name: OU=OU,OU=Test,DC=domain,DC=invalid but it seems both methods throw an error of 1... How do I specify the OU I want to move my Object to?

Anyone? Anyone? Bueller?

:idiot:

Posted

Run the _AD_SamAccountNameToFQDN.au3 example script.

You will see something like "CN=Name Firstname,OU=xx,..."

"OU=xx,..." is the FQDN for the OU.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Version 1.3.0.0 of the UDF has been released.

This version combines the last production version 1.2.0 and the experimental version 1.2.2.0!

Please test before using in production!

For download please see my signature.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

He estado tratando de bajar la UDFpara active directory, alguien me la puede proporcionar por favor o decirme de donde l,a puedo bajar correctamente.

I've been trying to lose the UDFpara active directory, anyone can provide me please or tell me where l, I can download correctly.

Posted

The download link for the UDF is on the of this thread.

Did you have any problems downloading the ZIP file?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Func _Adupdate()
GUISetState(@SW_HIDE, $MainGUI)
_AD_Open()
Local $newOU = $newTOU
Local $sTitle = "Active Directory Update"
#Region ### START Koda GUI section ### Form=
Local $hMain = GUICreate("sTitle", 413, 619, -1, -1)
GUICtrlCreateLabel("Move Computer To Selected OU And Auto Update Description In AD", 8, 2, 559, 21)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
Local $IObject = GUICtrlCreateInput(_AD_SamAccountNameToFQDN(@ComputerName & "$"), 8, 30, 559, 21)
GUICtrlSetState($IObject, $GUI_HIDE)
GUICtrlCreateLabel("Name Of Computer Being Moved And Updated:", 8, 99, 231, 21)
Local $ComputerToMove = GUICtrlCreateLabel(@ComputerName, 250, 99, 116, 21)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateLabel("Move The Above Computer To The Below Selected Organizational", 8, 132, 343, 21)
Local $Group1 = GUICtrlCreateGroup("Select Your Theatre Of Operation", 8, 24, 393, 65)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Local $USARadio = GUICtrlCreateRadio("USA", 16, 56, 81, 17)
Local $AfricaRadio = GUICtrlCreateRadio("Africa", 246, 56, 65, 17)
Local $hTree = GUICtrlCreateTreeView(6, 154, 400, 300, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetTip(-1, "Ensure you select the correct OU")
Local $bExit = GUICtrlCreateButton("Close", 5, 534, 400, 64)
GUICtrlSetImage(-1, "shell32.dll", 28)
Local $BOK = GUICtrlCreateButton("Move And Update", 5, 464, 400, 64)
GUICtrlSetTip(-1, "Once pressed, the computer will be moved to the selected OU" & @CRLF & _
"and the computer description auto populated into Active Directory.", "", 0, 1)
GUICtrlSetImage(-1, "shell32.dll", -89)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;Local $aTreeView = _AD_GetOUTreeView($newOU, $hTree)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$msg = GUIGetMsg()
Switch $msg
Case $USARadio, $AfricaRadio, $newTOU
If BitAND(GUICtrlRead($USARadio), $GUI_CHECKED) Then
$newTOU = ("OU=USA,DC=Domain,DC=com")
EndIf
If BitAND(GUICtrlRead($AfricaRadio), $GUI_CHECKED) Then
$newTOU = ("OU=Africa,DC=Domain,DC=com")
EndIf

EndSwitch
WEnd



Local $aTreeView = _AD_GetOUTreeView($newTOU, $hTree)

;-------------------------
;Pulls Local machine name
;-------------------------

Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $colItems = ""
Local $sComputer = "LocalHost"
Local $sDescription = ""
Local $objWMIService = ObjGet("winmgmts:" & $sComputer & "rootCIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
$sDescription = $objItem.Description & @CRLF
ExitLoop
Next
EndIf
; Open Connection to the Active Directory
_AD_Open()

While 1
Local $nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $bExit
GUIDelete($hMain)
GUISetState(@SW_SHOW, $MainGUI)
Return ""

Case $BOK
Local $sObject = GUICtrlRead($IObject)
Local $ssComputer = GUICtrlRead($ComputerToMove)
;Local $ssDescription = GUICtrlRead($sDescription) ;===========> Edited out first
Local $hSelection = _GUICtrlTreeView_GetSelection($hTree)
;Local $sSelection = _GUICtrlTreeView_GetText($hTree, $hSelection) ;===========> Edited out second
For $i = 1 To $aTreeView[0][0]
If $hSelection = $aTreeView[$i][2] Then ExitLoop
Next
Local $sOU = $aTreeView[$i][1]
ExitLoop
EndSwitch
WEnd
; Change attribute
$iValue = _AD_ModifyAttribute($ssComputer & "$", "description", $sDescription)
If $iValue = 1 Then
MsgBox(0, "Standby", "ADUpdate is now updating the description and checking Active Directory reference the move request.", 5)
MsgBox(64, "Successful", "Changes for '" & $ssComputer & "' were successfully completed.")
ElseIf @error = 1 Then
MsgBox(0, "Standby", "ADUpdate is now checking Active Directory.", 5)
MsgBox(64, "Active Directory Error", "Computer '" & $ssComputer & "' does not exist in AD")
Else
MsgBox(0, "Standby", "ADUpdate is now checking Active Directory.", 5)
MsgBox(64, "Active Directory Error", "Computer already in Active Directory")
;MsgBox(64, "Error", "Return code '" & @error & "' from Active Directory")
EndIf

; Move object
$iValue = _AD_MoveObject($sOU, $sObject)
If $iValue = 1 Then
; MsgBox(64, "Computer Move", "Computer Successfully Moved!")
ElseIf @error = 1 Then
MsgBox(64, "Active Directory Error", "Target OU '" & $sOU & "' does not exist in AD")
ElseIf @error = 2 Then
MsgBox(64, "Active Directory Error", "Object '" & $sObject & "' does not exist in AD")
Else
MsgBox(64, "Active Directory Error", "Computer already in that OU")
;MsgBox(64, "Active Directory Functions - Example 1", "Return code '" & @error & "' from Active Directory")
EndIf
_AD_Close()
GUIDelete($hMain)
GUISetState(@SW_SHOW, $MainGUI)
EndFunc ;==>_Adupdate

Func _AD_GetOUTreeView($sAD_OU, $hAD_TreeView, $bAD_IsADOpen = True)

If $bAD_IsADOpen = False Then
_AD_Open()
If @error Then Return SetError(@error, @extended, 0)
EndIf
Local $sSeparator = ""
Local $aAD_OUs = _AD_GetAllOUs($sAD_OU, $sSeparator)
If @error <> 0 Then Return SetError(@error, @extended, 0)
Local $aAD_TreeView[$aAD_OUs[0][0] + 1][3] = [[$aAD_OUs[0][0], 3]]
For $i = 1 To $aAD_OUs[0][0]
Local $aAD_Temp = StringSplit($aAD_OUs[$i][0], $sSeparator)
$aAD_TreeView[$i][0] = StringFormat("%" & $aAD_Temp[0] - 1 & "s", "") & "#" & $aAD_Temp[$aAD_Temp[0]]
$aAD_TreeView[$i][1] = $aAD_OUs[$i][1]
Next
If $bAD_IsADOpen = False Then _AD_Close()
_GUICtrlTreeView_BeginUpdate($hAD_TreeView)
Local $ahAD_Node[50]
For $iAD_Index = 1 To $aAD_TreeView[0][0]
Local $sAD_Line = StringSplit(StringStripCR($aAD_TreeView[$iAD_Index][0]), @TAB)
Local $iAD_Level = StringInStr($sAD_Line[1], "#")
If $iAD_Level = 0 Then ExitLoop
Local $sDescription = _AD_GetobjectAttribute($aAD_OUs[$iAD_Index][1], "description") ; <=== Adds the description to the OU Tree
If $iAD_Level = 1 Then
$ahAD_Node[$iAD_Level] = _GUICtrlTreeView_Add($hAD_TreeView, 0, StringMid($sAD_Line[1], $iAD_Level + 1) & " - " & $sDescription)
$aAD_TreeView[$iAD_Index][2] = $ahAD_Node[$iAD_Level]
Else
$ahAD_Node[$iAD_Level] = _GUICtrlTreeView_AddChild($hAD_TreeView, $ahAD_Node[$iAD_Level - 1], StringMid($sAD_Line[1], $iAD_Level + 1) & " - " & $sDescription)
$aAD_TreeView[$iAD_Index][2] = $ahAD_Node[$iAD_Level]
EndIf
Next
_GUICtrlTreeView_EndUpdate($hAD_TreeView)
Return $aAD_TreeView
EndFunc ;==>_AD_GetOUTreeView
Hi Water

I'm still struggling to restrict what is visable in the AD tree using radio buttons I'm afraid, probably because I'm way off finding a solution.

Full code above, any advise will be most welcome

Edited by Iceman682
Posted (edited)

Just had a quick look at your code.

Shouldn't this line

Case $USARadio, $AfricaRadio, $newTOU
read
Case $USARadio, $AfricaRadio
because $newTOU isn't a GUI control.

Edit: I will have to test your code tomorrow when I'm in my office again.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Ok, this example let's you select the target OU. Click on "Move and Update" and a MsgBox will show the selected OU.

If I look at your code above it's a bit of a "mess". There are too many calls to _AD_Open, too many loops processing the GUI input etc.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <ad.au3>

_AD_ErrorNotify(2)
_AD_Open()
_AD_Update()
_AD_Close()

Func _Ad_Update()
    Local $newTOU
    Local $sTitle = "Active Directory Update"
    #region ### START Koda GUI section ### Form=
    Local $hMain = GUICreate("sTitle", 413, 619, -1, -1)
    GUICtrlCreateLabel("Move Computer To Selected OU And Auto Update Description In AD", 8, 2, 559, 21)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x0000FF)
    GUICtrlCreateLabel("Name Of Computer Being Moved And Updated:", 8, 99, 231, 21)
    Local $ComputerToMove = GUICtrlCreateLabel(@ComputerName, 250, 99, 116, 21)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFF0000)
    GUICtrlCreateLabel("Move The Above Computer To The Below Selected Organizational Unit", 8, 132, 343, 21)
    Local $Group1 = GUICtrlCreateGroup("Select Your Theatre Of Operation", 8, 24, 393, 65)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    Local $USARadio = GUICtrlCreateRadio("USA", 16, 56, 81, 17)
    Local $AfricaRadio = GUICtrlCreateRadio("Africa", 246, 56, 65, 17)
    Local $hTree = GUICtrlCreateTreeView(6, 154, 400, 300, -1, $WS_EX_CLIENTEDGE)
    GUICtrlSetTip(-1, "Ensure you select the correct OU")
    Local $bExit = GUICtrlCreateButton("Close", 5, 534, 400, 64)
    GUICtrlSetImage(-1, "shell32.dll", 28)
    Local $BOK = GUICtrlCreateButton("Move And Update", 5, 464, 400, 64)
    GUICtrlSetTip(-1, "Once pressed, the computer will be moved to the selected OU" & @CRLF & _
            "and the computer description auto populated into Active Directory.", "", 0, 1)
    GUICtrlSetImage(-1, "shell32.dll", -89)
;    GUICtrlSetColor(-1, 0xC0C0C0)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $USARadio, $AfricaRadio
                If BitAND(GUICtrlRead($USARadio), $GUI_CHECKED) Then $newTOU = "OU=USA,DC=Domain,DC=com"
                If BitAND(GUICtrlRead($AfricaRadio), $GUI_CHECKED) Then $newTOU = "OU=Africa,DC=Domain,DC=com"
                _GUICtrlTreeView_DeleteAll($hTree)
                $aTreeView = _AD_GetOUTreeView($newTOU, $hTree, True, False, True, "", "", 2)
            Case $BOK
                $hSelection = _GUICtrlTreeView_GetSelection($hTree)
                $sSelection = _GUICtrlTreeView_GetText($hTree, $hSelection)
                For $i = 1 To $aTreeView[0][0]
                    If $hSelection = $aTreeView[$i][2] Then ExitLoop
                Next
                $sOU = $aTreeView[$i][1]
                MsgBox(64, $sTitle & " - Selected OU", "Name: " & $sSelection & @CRLF & "FQDN: " & $sOU)
            Case $bExit, $GUI_EVENT_CLOSE
                Return
        EndSwitch
    WEnd
EndFunc   ;==>_Ad_Update

; #FUNCTION# ====================================================================================================================
; Name...........: _AD_GetOUTreeView
; Description ...: Fills a given TreeView control with all OUs starting with a given OU.
; Syntax.........: _AD_GetOUTreeView($sAD_OU, $hAD_TreeView[, $bAD_IsADOpen = False[, $bAD_Count = False[, $bAD_Display = False[, $sAD_Category = ""[, $sAD_Text = " (%)"[, $iAD_SearchScope = 1]]]]]])
; Parameters ....: $sAD_OU        - FQDN of the OU where to start. "" displays all OUs
;                 $hAD_TreeView    - Handle of the TreeView where the OUs will be displayed. Has to be created in advance
;                 $bAD_IsADOpen    - Optional: Pass as True if the connection to the AD has already been made by the calling script (default = False)
;                 $bAD_Count       - Optional: True will display the count of objects in the OU right to the OU name (default = False)
;                                    The LDAP query to determine the count is built from $sAD_Category
;                 $bAD_Display   - Optional: True will display the objects in the OU below the OU itself (default = False)
;                 $sAD_Category    - Optional: Category to search for or the complete LDAP search string e.g. "computer" and "(objectcategory=computer)" are equivalent
;                                    The number of found objects is added to the OUs name (default = "" = don't count objects)
;                 $sAD_Text     - Optional: Text to display the count. Must contain a % which will be replaced by the actual number (default = " (%)")
;                 $iAD_SearchScope - Optional: Search scope for function _AD_GetObjectsInOU: 0 = base, 1 = one-level, 2 = sub-tree (default = 1)
; Return values .: Success - 1
;                 Failure - Returns 0 and sets @error:
;                 |x - Function _AD_Open or _AD_GetAllOUs failed. @error and @extended are set by _AD_Open or _AD_GetAllOUs
; Author ........: water bnased on code by ReFran - http://www.autoitscript.com/forum/topic/84119-treeview-read-to-from-file
; Modified.......: water including ideas by HaeMHuK
; Remarks .......: Use $iAD_SearchScope = 1 to get the number of objects of a single OU.
;                 Use $iAD_SearchScope = 2 to get the number of objects in the OU plus all sub-OUs.
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _AD_GetOUTreeView($sAD_OU, $hAD_TreeView, $bAD_IsADOpen = False, $bAD_Count = False, $bAD_Display = False, $sAD_Category = "", $sAD_Text = " (%)", $iAD_SearchScope = 1)

    Local $iAD_Count, $aObjects
    If $bAD_IsADOpen = False Then
        _AD_Open()
        If @error Then Return SetError(@error, @extended, 0)
    EndIf
    $sSeparator = ""
    Local $aAD_OUs = _AD_GetAllOUs($sAD_OU, $sSeparator)
    If @error <> 0 Then Return SetError(@error, @extended, 0)
    Local $aAD_TreeView[$aAD_OUs[0][0] + 1][3] = [[$aAD_OUs[0][0], 3]]
    Local $aAD_Result = $aAD_TreeView
    For $i = 1 To $aAD_OUs[0][0]
        $aAD_Temp = StringSplit($aAD_OUs[$i][0], $sSeparator)
        $aAD_TreeView[$i][0] = StringFormat("%" & $aAD_Temp[0] - 1 & "s", "") & "#" & $aAD_Temp[$aAD_Temp[0]]
        $aAD_TreeView[$i][1] = $aAD_OUs[$i][1]
    Next
    _GUICtrlTreeView_BeginUpdate($hAD_TreeView)
    Local $ahAD_Node[50], $sAD_LDAPString
    If $sAD_Category <> "" And StringIsAlNum($sAD_Category) Then
        $sAD_LDAPString = "(objectcategory=" & $sAD_Category & ")"
    Else
        $sAD_LDAPString = $sAD_Category
    EndIf
    $iAD_OutIndex = 0
    For $iAD_Index = 1 To $aAD_TreeView[0][0]
        $iAD_OutIndex += 1
        $aObjects = ""
        $sAD_Line = StringSplit(StringStripCR($aAD_TreeView[$iAD_Index][0]), @TAB)
        $iAD_Level = StringInStr($sAD_Line[1], "#")
        If $iAD_Level = 0 Then ExitLoop
        If ($bAD_Count Or $bAD_Display) And $sAD_LDAPString <> "" Then
            If $bAD_Display Then
                $aObjects = _AD_GetObjectsInOU($aAD_TreeView[$iAD_Index][1], $sAD_LDAPString, $iAD_SearchScope, "samaccountname,distinguishedname", "", False)
                If @error Then
                    $iAD_Count = 0
                Else
                    $iAD_Count = $aObjects[0][0]
                EndIf
            Else
                $iAD_Count = _AD_GetObjectsInOU($aAD_TreeView[$iAD_Index][1], $sAD_LDAPString, $iAD_SearchScope, "samaccountname,distinguishedname", "", True)
            EndIf
        EndIf
        $sAD_Temp = ""
        If $bAD_Count And $sAD_LDAPString <> "" Then $sAD_Temp = StringReplace($sAD_Text, "%", $iAD_Count)
        If $iAD_Level = 1 Then
            $ahAD_Node[$iAD_Level] = _GUICtrlTreeView_Add($hAD_TreeView, 0, StringMid($sAD_Line[1], $iAD_Level + 1) & $sAD_Temp)
        Else
            $ahAD_Node[$iAD_Level] = _GUICtrlTreeView_AddChild($hAD_TreeView, $ahAD_Node[$iAD_Level - 1], StringMid($sAD_Line[1], $iAD_Level + 1) & $sAD_Temp)
        EndIf
        $aAD_Result[$iAD_OutIndex][0] = $aAD_TreeView[$iAD_Index][0]
        $aAD_Result[$iAD_OutIndex][1] = $aAD_TreeView[$iAD_Index][1]
        $aAD_Result[$iAD_OutIndex][2] = $ahAD_Node[$iAD_Level]
        ; Add the objects of the OU to the TreeView
        If IsArray($aObjects) Then
            ReDim $aAD_Result[UBound($aAD_Result, 1) + $aObjects[0][0]][UBound($aAD_Result, 2)]
            For $iAD_Index2 = 1 To $aObjects[0][0]
                $iAD_OutIndex += 1
                If StringRight($aObjects[$iAD_Index2][0], 1) = "$" Then $aObjects[$iAD_Index2][0] = StringLeft($aObjects[$iAD_Index2][0], StringLen($aObjects[$iAD_Index2][0]) - 1)
                $aAD_Result[$iAD_OutIndex][0] = $aObjects[$iAD_Index2][0]
                $aAD_Result[$iAD_OutIndex][1] = $aObjects[$iAD_Index2][1]
                $aAD_Result[$iAD_OutIndex][2] = _GUICtrlTreeView_AddChild($hAD_TreeView, $ahAD_Node[$iAD_Level], $aObjects[$iAD_Index2][0])
            Next
        EndIf
    Next
    If $bAD_IsADOpen = False Then _AD_Close()
    _GUICtrlTreeView_EndUpdate($hAD_TreeView)
    $aAD_Result[0][0] = UBound($aAD_Result, 1) - 1
    $aAD_Result[0][1] = UBound($aAD_Result, 2)
    Return $aAD_Result

EndFunc   ;==>_AD_GetOUTreeView

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Thanks Water

After replacing the existing code with your code and editing the OU=, DC=, DC= to correspond with the domain details, for some reason I get the following error when selecting either radio button:

--------------------------------------------------------------------------------------------------

Line 540 (File "C:\Program Files\AutoIt3\Include\sAD.au3"):

$_oAD_Command.CommandTest = "<LDAP://&$sAD_HostServer &

"" & $sAD_DNSDomain & ">;( & $sAD_Property & "=" & $sAD_Object

$_oAD_Command^ ERROR

Error: Variable must be of the type "Object".

--------------------------------------------------------------------------------------------------

When I run it as a standalone I don't get the error but when I try and move a computer from one OU to another it doesn't move.

Many thanks in advance.

Edited by Iceman682
Posted

Make sure that you call function _AD_Open in your new script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

water,

I detected a problem with V1.3.0.0. If I use my own error handler UDF and place it after/before #include <AD.au3> then your UDF cannot connect to an AD any longer (@error = 3 / @extended = 3).

Here's a reproducer:

#include <Array.au3>

;~ #include "D:SUPERSONIC_AUTOITInclude_Various_ErrorHandler.au3"
Global $___ERRORHANDLER_AUTOITOBJECT = ObjEvent("AutoIt.Error", "_ErrorHandler")

#include <AD.au3>

_AD_Open()
If Not @error Then
Local $aTmp = _AD_ListDomainControllers()
If Not @error Then
_ArrayDisplay($aTmp, "$aTmp")
Else
MsgBox(0, "", @error & "___" & @extended)
EndIf
Else
MsgBox(0, "", @error & "___" & @extended)
EndIf

_AD_Close()

Func _ErrorHandler()
;;;
EndFunc

Did I something wrong?

Greets,

-supersonic.

Edited by supersonic
Posted

Version 1.3.0.0 of the UDF and a user defined COM error handler don't play together well.

If you run your script with the AutoIt beta >= 3.3.9.2 then everything will work well

Or you could uncomment line

; Activate the COM error handler for older AutoIt versions
If $__iAD_Debug = 0 And Number(StringReplace(@AutoItVersion, ".", "")) < 3392 Then _AD_ErrorNotify(1)
in function _AD_Open.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Hi,

thank you for sharing this great UDF :)

after an update from version 1.2.0 to 1.3.0.0

I use the function _AD_ObjectExists in 1.2.0, it is well with my user object in version 1.3.0.0 by cons, message that the user does not exist.

Posted

Which version of AutoIt do you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Guest
This topic is now closed to further replies.
×
×
  • Create New...