Jump to content

Help Please


Recommended Posts

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=AD Update 1.0.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Comment=Domain & AD Update Tool For Engineers
#AutoIt3Wrapper_Res_Description=AD Update
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Iceman
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Obfuscator=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <AD.au3>
#include <TreeviewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GuiTreeView.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <GUIButton.au3>
#include <GuiToolTip.au3>

Global $newOU, $aTreeView, $hSelection, $sSelection, $sOU, $sAdminUserName, $tPassword, $tCancel, $tStart
Global $msg, $MainGUI, $Result[3], $button[4], $DomainName, $dDomain, $sCompName, $dCompName, $sDomain, $RebootGUI
Global $AdminUserName, $Password, $Domain, $Description, $JoinGUI, $InputUserAdmin, $AddAdminButton
Global $iValue, $UserName, $strComputer, $objGroup, $objUser, $DeskTop, $Laptop, $localAdminsGUI
Global $UserAdmin, $UserPower, $HelpDesk, $InputPowerUser, $AddPUButton, $CancelButton

;-------------------------------------------------------------------------
; Password
;-------------------------------------------------------------------------

GUICreate("Login", 270, 130)
GUICtrlCreateLabel("Access Password:", 5, 20)
$tPassword = GUICtrlCreateInput("", 95, 15, 170, 20, $ES_PASSWORD)
GUICtrlSetTip(-1, "Case Sensitive", "", 0, 1)
$tCancel = GUICtrlCreateButton(" Cancel", 10, 45, 120, 64)
GUICtrlSetImage(-1, "shell32.dll", 28)
$tStart = GUICtrlCreateButton("Login", 140, 45, 120, 64)
GUICtrlSetImage(-1, "shell32.dll", 48)
GUICtrlCreateLabel("Created By Iceman", 85, 112, 108, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlCreateLabel("Version 1.0", 205, 112, 68, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
GUISetState()
GUICtrlSetState($tStart, $GUI_DEFBUTTON)
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then
Exit
ElseIf $msg = $tCancel Then
Exit
ElseIf $msg = $tStart Then
If Not (GUICtrlRead($tPassword) == "Password") Then
MsgBox(0, "", "Whoops, emptywrong password entered")
Else
GUISetState(@SW_HIDE)
ExitLoop
EndIf
EndIf
WEnd

;--------------------------------------------------------------------------------
;
; Main Menu GUI with all button selections
;
;--------------------------------------------------------------------------------

_MainGUI()
Func _MainGUI()
$MainGUI = GUICreate("Menu", 260, 325) ; will create a dialog box that when displayed is centered
GUICtrlCreateLabel("Please select from the options below:", 5, 10, 600, 17)
GUICtrlSetFont(-1, 9, 800); bold
$button[0] = GUICtrlCreateButton(" Join The Computer To The Domain", 5, 30, 250, $BS_ICON, $WS_GROUP)
GUICtrlSetImage(-1, "shell32.dll", 40)
$button[1] = GUICtrlCreateButton(" Add Local Admins And Power Users", 5, 170, 250, $BS_ICON, $WS_GROUP)
GUICtrlSetImage(-1, "dskquoui.dll", -3)
$button[2] = GUICtrlCreateButton(" Update Active Directory", 5, 100, 250, $BS_ICON, $WS_GROUP)
GUICtrlSetImage(-1, "localsec.dll", -12)
$button[3] = GUICtrlCreateButton(" Exit", 5, 240, 250, $BS_ICON, $WS_GROUP)
GUICtrlSetImage(-1, "shell32.dll", 28)
$DomainName = @LogonDomain
$dCompName = @ComputerName
If $DomainName = $dCompName Then
GUICtrlSetState($button[0], $GUI_ENABLE)
GUICtrlSetState($button[1], $GUI_DISABLE)
GUICtrlSetState($button[2], $GUI_DISABLE)
Else
GUICtrlSetState($button[0], $GUI_DISABLE)
GUICtrlSetState($button[1], $GUI_ENABLE)
GUICtrlSetState($button[2], $GUI_ENABLE)
EndIf
GUICtrlCreateLabel("Created By Iceman", 85, 305, 108, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlCreateLabel("Version 1.0", 200, 305, 108, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE, $button[3]
Exit
Case $button[0]
_JoinGUI()
Case $button[1]
_Add_Usr2Grp()
Case $button[2]
_ADUpdate()
EndSwitch
WEnd
EndFunc ;==>_MainGUI

;-------------------------------------------------------
; Main Domain Joining GUI
; Buttons are only usable within this part of the script
;-------------------------------------------------------

Func _JoinGUI()
GUISetState(@SW_HIDE, $MainGUI)
#region ###
$JoinGUI = GUICreate("Domain Joining", 300, 250)
GUICtrlCreateLabel("ALL Fields MUST Be Complete:", 5, 10, 600, 17)
GUICtrlSetFont(-1, 9, 800); bold
GUICtrlCreateLabel("Admin User Name:", 5, 40)
$AdminUserName = GUICtrlCreateInput("", 125, 35, 170, 20)
GUICtrlCreateLabel("Admin Password:", 5, 70)
$Password = GUICtrlCreateInput("", 125, 65, 170, 20, $ES_PASSWORD)
GUICtrlCreateLabel("Domain Name:", 5, 100)
$Domain = GUICtrlCreateInput("Domain.local", 125, 95, 170, 20) ;============> Change when moving domains
GUICtrlCreateLabel("Computer Description:", 5, 130)
$Description = GUICtrlCreateInput("", 125, 125, 170, 20)
GUICtrlSetTip(-1, "This will be auto inserted into AD" & @CRLF & _
"during the update Active Directory phase.", "", 0, 1)
Local $CancelButton = GUICtrlCreateButton(" Close", 20, 170, 120, $BS_ICON, $WS_GROUP)
GUICtrlSetImage(-1, "shell32.dll", 28)
Local $Joinbutton = GUICtrlCreateButton(" Join", 160, 170, 120, $BS_ICON, $WS_GROUP)
GUICtrlSetImage(-1, "shell32.dll", -138)
GUICtrlSetTip(-1, "Once pressed, you will received a successfailure notification.", "", 0, 1)
GUICtrlSetState($Joinbutton, $GUI_DISABLE)
GUICtrlCreateLabel("Created By Iceman", 100, 236, 108, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlCreateLabel("Version 1.0", 240, 236, 108, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#endregion ###

;--------------------------------------------------------------------
; Only when all fields are complete will the Join button be active
;--------------------------------------------------------------------

While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE, $CancelButton
GUIDelete($JoinGUI)
GUISetState(@SW_SHOW, $MainGUI)
Return ""
Case $Description, $AdminUserName, $Password, $Domain
Local $sAdminUserName = GUICtrlRead($AdminUserName)
Local $sPassword = GUICtrlRead($Password)
$sDomain = GUICtrlRead($Domain)
Local $sDescription = GUICtrlRead($Description)
If $sAdminUserName <> "" And $sPassword <> "" And $sDomain <> "" And $sDescription <> "" Then
GUICtrlSetState($Joinbutton, $GUI_ENABLE)
Else
GUICtrlSetState($Joinbutton, $GUI_DISABLE)
EndIf
Case $Joinbutton
_DomainJoin()
EndSwitch
WEnd
EndFunc ;==>_JoinGUI

;------------------------------------------------------------------------------------
; Auto Joins a Windows XP And 7 Machine to the domain
; You will need to insert the Administrator Credentails at the Aunthentication stage.
;------------------------------------------------------------------------------------

Func _DomainJoin()
Local $JOIN_DOMAIN = 1
Local $ACCT_CREATE = 2
Local $strAdminPass = GUICtrlRead($Password)
Local $strAdminAccount = GUICtrlRead($AdminUserName)
Local $strComputer = @ComputerName
Local $strDomainName = "Domain.local" ;=======> Change this when moving domains
Local $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!" & $strComputer & "rootcimv2")
Local $colCompSystems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For $objCompSystem In $colCompSystems

;-------------------------------------
; Change Computer Description
;--------------------------------------
Local $sDescription = GUICtrlRead($Description)
RegWrite("HKLMSYSTEMCurrentControlSetServicesLanmanserverparameters", "srvcomment", "REG_SZ", $sDescription)
Local $temp = MsgBox(1, 'Joining Domain', "Attempting to join " & $strComputer & " to the " & $strDomainName & " Domain")
If $temp = 2 Then
Return
EndIf
Local $intJoinDomain = $objCompSystem.JoinDomainOrWorkgroup($strDomainName, $strAdminPass, $strDomainName & '' & $strAdminAccount, '', $JOIN_DOMAIN + $ACCT_CREATE)
If $intJoinDomain = 0 Then
GUIDelete($JoinGUI)
#region ### START Koda GUI section ### Form=
$RebootGUI = GUICreate("Reboot.", 376, 115)
GUICtrlCreateIcon("C:\Windows\System32\shell32.dll", -238, 16, 40, 32, 32)
GUICtrlCreateLabel("System will automatically reboot", 72, 32, 300, 28)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateLabel("in 1 minute to complete the Domain", 72, 56, 284, 28)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateLabel("Joining Process - No action required.", 72, 80, 294, 28)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateLabel("This system has successfully joined the domain.", 3, 3, 370, 28)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Sleep(60000)
Shutdown(2, "Rebooting after Domain Join") ;Force a reboot *****Removed for testing*******

ElseIf $intJoinDomain = 1 Then
MsgBox(0, "Failure", "Unable to Join Computer to " & $strDomainName & " Domain." & @CRLF & _GetExitCode($intJoinDomain))
Else
MsgBox(0, "Failure", "Unable to Join Computer to " & $strDomainName & " Domain." & @CRLF & _GetExitCode($intJoinDomain))
EndIf
Next
EndFunc ;==>_DomainJoin

Func _GetExitCode($iExitCode)
Local $sLine = ''
Local $Pid = Run(@ComSpec & " /c net helpmsg " & $iExitCode, @SystemDir, @SW_HIDE, 2)
While 1
$sLine &= StdoutRead($Pid)
If @error Then ExitLoop
WEnd
Local $strErrorMessage = "ErrorCode: " & $iExitCode & " " & StringStripWS(StringStripCR($sLine), 3)
Return ($strErrorMessage)

EndFunc ;==>_GetExitCode

;------------------------------------------------------------------------------------
; Add accounts to the Administrators and/or the Power User Groups
;------------------------------------------------------------------------------------

Func _Add_Usr2Grp()
GUISetState(@SW_HIDE, $MainGUI)
#region ### START Koda GUI section ###
$localAdminsGUI = GUICreate("Add Local Admins And Power Users", 395, 528)
GUICtrlCreateGroup("Select Computer Type", 10, 10, 372, 60)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$DeskTop = GUICtrlCreateRadio("Desktop", 40, 32, 65, 25)
GUICtrlSetTip(-1, "User Will Be Added To The Local Power Users Group")
$Laptop = GUICtrlCreateRadio("Laptop", 156, 32, 209, 25)
GUICtrlSetTip(-1, "User Will Be Added To The Local Administrators Group")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("User Account To Be Added To The Local Administrators Group", 10, 179, 372, 130)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("User Name:", 20, 227, 134, 17)
$InputUserAdmin = GUICtrlCreateInput("", 130, 222, 140, 21)
GUICtrlSetState($InputUserAdmin, $GUI_DISABLE)
$AddAdminButton = GUICtrlCreateButton(" Add", 281, 202, 88, 64, BitOR($BS_DEFPUSHBUTTON, $BS_NOTIFY))
GUICtrlSetTip(-1, "Ensure you insert a valid User Name" & @CRLF & _
"as it will be checked against Active Directory", "", 0, 1)
GUICtrlSetImage(-1, "dskquoui.dll", -3)
GUICtrlCreateLabel("Only valid Active Directory accounts will be added", 53, 280, 310, 17)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetState($AddAdminButton, $GUI_DISABLE)
GUICtrlCreateGroup("User Account To Be Added To The Power Users Group", 10, 314, 372, 119)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("User Name:", 20, 359, 134, 17)
$InputPowerUser = GUICtrlCreateInput("", 130, 356, 140, 21)
GUICtrlSetState($InputPowerUser, $GUI_DISABLE)
$AddPUButton = GUICtrlCreateButton(" Add", 281, 334, 88, 64)
GUICtrlSetTip(-1, "Ensure you insert a valid User Name" & @CRLF & _
"as it will be checked against Active Directory", "", 0, 1)
GUICtrlSetImage(-1, "dskquoui.dll", -3)
GUICtrlCreateLabel("Only valid Active Directory accounts will be added", 53, 408, 310, 17)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetState($AddPUButton, $GUI_DISABLE)
$CancelButton = GUICtrlCreateButton(" Close", 10, 438, 372, 64)
GUICtrlSetImage(-1, "shell32.dll", 28)
GUICtrlCreateLabel("Created By Iceman", 143, 510, 108, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlCreateLabel("Version 1.0", 326, 510, 68, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlCreateGroup("Admin Accounts To Add To The Local Administrator Group", 10, 80, 372, 89)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("HelpDesk Is Added By Default To The Machine", 50, 105, 304, 20)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateLabel("DefaultAdmins Are Auto Added By Group Policy To The Machine", 25, 130, 350, 20)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$HelpDesk = ("HelpDesk")
$UserAdmin = ($InputUserAdmin)
$UserPower = ($InputPowerUser)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE, $CancelButton
GUIDelete($localAdminsGUI)
GUISetState(@SW_SHOW, $MainGUI)
Return ""
Case $DeskTop, $Laptop
If BitAND(GUICtrlRead($DeskTop), $GUI_CHECKED) Then
GUICtrlSetState($InputUserAdmin, $GUI_DISABLE)
GUICtrlSetState($AddAdminButton, $GUI_DISABLE)
GUICtrlSetState($InputPowerUser, $GUI_ENABLE)
GUICtrlSetState($AddPUButton, $GUI_ENABLE)
EndIf
If BitAND(GUICtrlRead($Laptop), $GUI_CHECKED) Then
GUICtrlSetState($InputUserAdmin, $GUI_ENABLE)
GUICtrlSetState($AddAdminButton, $GUI_ENABLE)
GUICtrlSetState($InputPowerUser, $GUI_DISABLE)
GUICtrlSetState($AddPUButton, $GUI_DISABLE)
EndIf
Case $InputUserAdmin, $InputPowerUser
Case $AddAdminButton
If GUICtrlRead($InputUserAdmin) = '' Then
MsgBox(262144, "Entry Missing", "You must enter a User Name!")
Else
_AddAdmins(GUICtrlRead($InputUserAdmin))
EndIf
Case $AddPUButton
If GUICtrlRead($InputPowerUser) = '' Then
MsgBox(262144, "Entry Missing", "You must enter a User Name!")
Else
_AddPowerUsers(GUICtrlRead($InputPowerUser))
EndIf
EndSwitch
WEnd
EndFunc ;==>_Add_Usr2Grp

Func _AddAdmins($InputUserAdmin)
GUISetState(@SW_HIDE, $localAdminsGUI)
RunWait(@ComSpec & " /c " & "Net localgroup Administrators " & $HelpDesk & " /add", "", @SW_HIDE)
RunWait(@ComSpec & " /c " & "Net localgroup Administrators " & $InputUserAdmin & " /add", "", @SW_HIDE)
MsgBox(0, "", "Authorised accounts successfully added to the Administrators Group")
GUISetState(@SW_SHOW, $localAdminsGUI)
EndFunc ;==>_AddAdmins

Func _AddPowerUsers($InputPowerUser)
GUISetState(@SW_HIDE, $localAdminsGUI)
RunWait(@ComSpec & " /c " & "Net localgroup Administrators " & $HelpDesk & " /add", "", @SW_HIDE)
RunWait(@ComSpec & " /c " & '"Net localgroup "Power Users" "' & $InputPowerUser & " /add", "", @SW_HIDE)
MsgBox(0, "", "Authorised accounts successfully added to the Administrators and Power User Group")
GUISetState(@SW_SHOW, $localAdminsGUI)
EndFunc ;==>_AddPowerUsers

;------------------------------------------------------------------------------------
; Add the Machine to the selected Organization Unit in Active Directory
; Auto Updates the Computer Description Within Active Directory
;------------------------------------------------------------------------------------

Func _Adupdate()
GUISetState(@SW_HIDE, $MainGUI)
_AD_Open()
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)
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)
GUICtrlCreateGroup("Select Your Theatre", 8, 24, 393, 65)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Local $AmericaRadio = GUICtrlCreateRadio("America", 15, 56, 81, 17)
Local $AsiaRadio = GUICtrlCreateRadio("Asia", 110, 56, 65, 17)
Local $EuropeRadio = GUICtrlCreateRadio("Europe", 205, 56, 65, 17)
Local $SARadio = GUICtrlCreateRadio("SouthAmerica", 300, 56, 81, 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)
GUICtrlSetImage(-1, "shell32.dll", -89)
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)
GUICtrlCreateLabel("Created By Iceman", 150, 600, 108, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlCreateLabel("Version 1.0", 350, 600, 68, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

;-------------------------
;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

While 1
Local $nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $bExit
GUIDelete($hMain)
GUISetState(@SW_SHOW, $MainGUI)
Return ""
Case $AmericaRadio, $AsiaRadio, $EuropeRadio, $SARadio
If BitAND(GUICtrlRead($AmericaRadio), $GUI_CHECKED) Then $newTOU = "OU=America,DC=domain,DC=local"
If BitAND(GUICtrlRead($AsiaRadio), $GUI_CHECKED) Then $newTOU = "OU=Asia,DC=domain,DC=local"
If BitAND(GUICtrlRead($EuropeRadio), $GUI_CHECKED) Then $newTOU = "OU=Europe,DC=domain,DC=local"
If BitAND(GUICtrlRead($SARadio), $GUI_CHECKED) Then $newTOU = "OU=SouthAmerica,DC=domain,DC=local"
_GUICtrlTreeView_DeleteAll($hTree)
$aTreeView = _AD_GetOUTreeView($newTOU, $hTree)
Case $BOK
Local $sObject = GUICtrlRead($IObject)
Local $ssComputer = GUICtrlRead($ComputerToMove)
Local $hSelection = _GUICtrlTreeView_GetSelection($hTree)
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, "Please Standby", "now updating the description and checking Active Directory reference the move request.", 5)
MsgBox(64, "Success", "Changes for '" & $ssComputer & "' were successfully completed.")
ElseIf @error = 1 Then
MsgBox(0, "Please Standby", "now checking Active Directory.", 5)
MsgBox(64, "Active Directory Error", "Computer '" & $ssComputer & "' does not exist in AD")
Else
MsgBox(0, "Please Standby", "now checking Active Directory.", 5)
MsgBox(64, "Active Directory Error", "Computer already in 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")
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 Everyone

I am totally new to Autoit and scripting so please be gentle :)

I have managed to put together a script piece by piece and I am hoping that all those with the knowledge and expertise which is far more than I will ever have would kindly help me tidy,improve,update this script.

The script works but is a total mess and for some reason is slower within a physical domain enviroment than a virtual one.

Above is the full script.

Thanking those in advance for their help and assistance

Iceman

Edited by Iceman682
Link to comment
Share on other sites

Didn't see any obvious problems!

Your script is quite perfect.

But everyone else who needs a similar tool could have a look at my Active Directory Example Scripts thread. There is a tool named ADAT (Active Directory Administration Tool) which was designed to be easily expandable. Every function has its own tab and a clearly structured function which is called when you press OK on the tab.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

Hi Iceman,

most of the time you get better results if you can ask a precise question.

Means: If you get an error message, some code doesn't give you the expected results or is too slow.

If your code does everything you need, then it's just ... perfect :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

63 views and only 1 reply, is there no one else able to help apart from Water?

Come on guys help me out here!

Why not look at the problem from an 'outside' perspective. Your 'issue' is a little specific, though vague in what errors you have. Many people in the forum would help, but don't work in a domain environment. Therefore, they are not lazy, they just don't want to send you on 'wild goose chase' or provide incorrect answers.

Also some friendly advice, insulting those that help around here or begging for help is anti-productive to solving your issue.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thank you for your friendly advice and assistance.

I don't revieve any errors, it's very inconsitant to be honest, when I start the script, someimes it can take upto 30 seconds to get to the login GUI, other times it's instant. The same with all the other GUI's within the script, sometimes instant, other times can take upto 30 seconds to open. So I'm a little puzzeled as to why.

Edited by Iceman682
Link to comment
Share on other sites

I have a similar problem here. When I close a script that connects to AD it takes about 30 seconds for the script to finish. That means the GUI is closed but I can see the script for about 30 seconds on the list of running tasks.

Wasn't able to determine why this happens (but didn't try too hard). I suspect it's the virus scan or HIPS.

This only happens on Windows 7, on Windows XP the task end immediately. I'm running the same exe on both systems.

Can you start and end your application and see how long the script stays on the task list?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

When I open the app, sometimes it open instantly and I can see it in the task list and sometimes it opens after around 30 seconds and is visible in the task list after round 30 seconds, closing it is not an issue, no delays

The point is the script isn't even connecting to AD at this point, all it's doing initailly is opening to a login screen to access the application.

Good point ref AntiVirus scanning

Edited by Iceman682
Link to comment
Share on other sites

Can you reproduce this behaviour?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

A few things I would try:

  • Remove the UPX compression
  • Remove the #RequireAdmin
  • Remove the GUICtrlSetImage(-1, "shell32.dll", 28) statements
  • Set the full path to "shell32.dll" in the GUICtrlSetImage statements: @SystemDir & "shell32.dll"

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

I've noticed that when I'm required to have a lot of 'include'(s) in my programs, startup times vary. I would suspect because the includes usually load global variables into memory, on top of the 38 global variables and 2 global arrays you've declared at the beginning of the script may cause some slowdowns as well.

I try to keep any script down to utilizing global variables only for the main GUI (GUI handle/Control handles), the script title, and the handle to a log file. Everything else should be localized and passed to functions.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

It seems to be the GUISetIcon statement which is my fault for omitting it from the orginal code, when removed from all the GUI's it's almost instant.

Are these icon's embedded in the .exe? becuase if not, that would explain it trying to find the icon where the source is not reachable when used on another network.

Is there a way to remove the default icon from the GUI's?

Apologies for wasting everyone's time.

Edited by Iceman682
Link to comment
Share on other sites

Why not use #AutoIt3Wrapper_Icon to set the exe icon? As I couldn't see GUISetIcon in your example.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

It seems I have found a slight issue that hopefully someone could assist.

When the move and update button is pressed without selecting an OU from the OU tree it returns an error:

Line 10160 (file "path to .exe")

Error: Array variable has incorrect number of subscripts or subscript dimention range exceeded.

Any assistance will be most welcome

Link to comment
Share on other sites

After line

Case $BOK
you have to check that $hSelection is not 0. 0 means that no selection has been made. In this case I would show a MsgBox.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

After line

Local $hSelection = _GUICtrlTreeView_GetSelection($hTree)
check that $hSelection <> 0. If 0 display a MsgBox and continue the loop.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...