darkleton Posted September 29, 2010 Share Posted September 29, 2010 i have an active directory tool that will list users in an OU. if you select one it will show details about that user, including the path to their home folder. What I wanted was for a button below it to let you click and open that home area in windows explorer. i have other buttons that will work on one user, you can then select another user and it will allow the same function on them (reset password for example). the problem is, it will run explorer once but if i select another user, it wont do anything, the whole script stops. i have the same layout for both buttons so can't see why its not working This is a cut down version of the function, and the $namebutton works on multiple accounts, the $homebutton doesn't. any ideas would be greatly appreciated. Func UpdateUserName() While 1 $msg = GUIGetMsg() Select Case $msg = $namebutton $newfn = GUICtrlRead($fnbox) $newsn = GUICtrlRead($snbox) $newname = GUICtrlRead($namebox) _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.Put ("givenName", $newfn) $ObjUser.Put ("sn", $newsn) $ObjUser.Put ("displayName", $newname) $ObjUser.SetInfo () _AD_Close() MsgBox(0,"","Name information updated successfully") UpdateUserName() Case $msg = $homebutton $homedir = GUICtrlRead($homedirbox) Run("explorer.exe /n," & $homedir) UpdateUserName() As I said, all other functions of the tool work, and i can select users countless times and run the other buttons, its only the homebutton, which is the only one which runs an external command. i thought it might have been because it was run, so tried runwait, shellexecute, but all just open it once then never run again. Thanks Mike Link to comment Share on other sites More sharing options...
wakillon Posted September 29, 2010 Share Posted September 29, 2010 (edited) Try $homedir = GUICtrlRead ( $homedirbox ) ConsoleWrite ( "$homedir : " & $homedir & @Crlf ) Run ( "explorer.exe /n," & $homedir )for see $homedir valuebut fullscript will be more helpfull ! Edited September 29, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
water Posted September 29, 2010 Share Posted September 29, 2010 Did you make sure that the script really stops at this point? Could you insert a consolewrite in front of the run statement? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
darkleton Posted September 29, 2010 Author Share Posted September 29, 2010 (edited) the homedir value actually works, as it opens explorer with the folder correctly, it is just if i then try to open another users folder it doesn't. water: the script doesn't stop no, it carries on (which just reruns the updateusername() func again waiting for another button to be pressed. like i said, all other buttons have the same layout (command/rerun function) and work fine. this is the entire script (which hasn't been tidied up yet as i had ripped this part out of another script i had) but as i said other functionality works, it is only the homedir thing. to replicate error: open program select user press > button click open home area button (this works multiple times on the same user) select another user click > button click open home area button again expandcollapse popup#include <GuiListBox.au3> #include <ListBoxConstants.au3> #Include <GUIConstants.au3> #Include <GuiListView.au3> #include <WindowsConstants.au3> #include <ad.au3> #include <Constants.au3> #Include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <array.au3> Const $ouIdentifier = "OU=" Const $cnIdentifier = "CN=" Const $ouSeparator = "\" Const $ADS_PROPERTY_UPDATE = 2 Dim $listmenu, $treemenu, $listselect Dim $userlabel, $userinput, $fnlabel, $snlabel, $fnbox, $snbox Dim $namebox, $namelabel, $namebutton, $passlabel, $passbox Dim $passbutton, $desclabel, $descbox, $descbutton, $homedirlabel Dim $homedirbox, $logonlabel, $logonbutton, $logonbox Dim $accntstatuslabel, $accntdisablebox, $accntstatusbutton Dim $ObjUser, $ObjComp, $homebutton Global $gui = GUICreate("OU Browser",570,600) Global $listmenu = GUICtrlCreateList("", 5, 5, 295, 595) Global $listselect = GUICtrlCreateButton(">",305,240,25) GUISetBkColor("0xA0A0A0") $currobjclass = "" UpdateList() GUISetState() $checktree = GUICtrlRead ($treemenu) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $listselect GetObjectClass() EndSelect WEnd Func UpdateList() GUICtrlSetData($listmenu,"") GUICtrlSetData($listmenu,"Updating list....please wait") _AD_Open() $arList = _AD_GetObjectsInOU("", "(&(objectclass=user)(objectCategory=person))", "", "sAMAccountName", "sAMAccountName") _AD_Close() GUICtrlSetData($listmenu, "|" & _ArrayToString($arList, "|", 1)) EndFunc Func GetObjectClass() $listselection = GUICtrlRead($listmenu, 1) _AD_Open() $listclass = _AD_GetObjectClass($listselection) _AD_Close() Select Case $listclass = "user" If $currobjclass = "" or "user" Then DeleteUserBoxes() UpdateUserInfo() UpdateUserName() Else UpdateUserInfo() EndIf EndSelect EndFunc Func UpdateUserInfo() _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) _AD_Close() $userlabel = GUICtrlCreateLabel("Username: ", 345, 25, 120, 25) $userinput = GUICtrlCreateInput($username,345,45,207,20,0x0800) $fnlabel = GUICtrlCreateLabel("First Name: ", 345, 80, 120, 25) $snlabel = GUICtrlCreateLabel("Surname: ", 460, 80, 120, 25) $fnbox = GUICtrlCreateInput($objUser.givenName, 345, 100,90,20) $snbox = GUICtrlCreateInput($objUser.sn, 460, 100, 90, 20) $namelabel = GUICtrlCreateLabel("Display Name: ",345, 130,120,25) $namebox = GUICtrlCreateInput($objUser.displayName, 345, 150, 150, 20) Global $namebutton = GUICtrlCreateButton("Update name details",345,175,120,20) Global $passbutton = GUICtrlCreateButton("Reset password",390,237,100,30) $desclabel = GUICtrlCreateLabel("Description: ", 345, 309, 120, 25) $descbox = GUICtrlCreateInput($objUser.description, 345,329,207,20) Global $descbutton = GUICtrlCreateButton("Update Description",345,354,120,20) $homedirlabel = GUICtrlCreateLabel("Home Directory: ", 345, 400, 120, 25) $homedirbox = GUICtrlCreateInput ($objUser.homeDirectory, 345,420,207,20,0x0800) Global $homebutton = GUICtrlCreateButton("Open Home Directory",345,445,120,20) GUICtrlSetFont($userlabel, Default, 600) GUICtrlSetFont($fnlabel, Default, 600) GUICtrlSetFont($snlabel, Default, 600) GUICtrlSetFont($namelabel, Default, 600) GUICtrlSetFont($passlabel, Default, 600) GUICtrlSetFont($desclabel, Default, 600) GUICtrlSetFont($homedirlabel, Default, 600) GUICtrlSetFont($logonlabel, Default, 600) GUICtrlSetFont($accntstatuslabel, Default, 600) EndFunc Func DeleteUserBoxes() GUICtrlDelete($userlabel) GUICtrlDelete($userinput) GUICtrlDelete($fnlabel) GUICtrlDelete($snlabel) GUICtrlDelete($fnbox) GUICtrlDelete($snbox) GUICtrlDelete($namebox) GUICtrlDelete($namelabel) GUICtrlDelete($namebutton) GUICtrlDelete($passlabel) GUICtrlDelete($passbox) GUICtrlDelete($passbutton) GUICtrlDelete($desclabel) GUICtrlDelete($descbox) GUICtrlDelete($descbutton) GUICtrlDelete($homedirlabel) GUICtrlDelete($homedirbox) GUICtrlDelete($logonlabel) GUICtrlDelete($logonbox) GUICtrlDelete($logonbutton) GUICtrlDelete($accntstatuslabel) GUICtrlDelete($accntdisablebox) GUICtrlDelete($accntstatusbutton) EndFunc Func UpdateComputerInfo() _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $pcfqdn = _AD_SamAccountNameToFQDN($listselection) $pcname = _AD_FQDNToSamAccountName($pcfqdn) $ObjComp = ObjGet("LDAP://" & $pcfqdn) $objCompStatus = $ObjComp.AccountDisabled MsgBox(0,"","computer status is " & $objCompStatus) _AD_Close() EndFunc Func UpdateUserName() While 1 $msg = GUIGetMsg() Select Case $msg = $namebutton $newfn = GUICtrlRead($fnbox) $newsn = GUICtrlRead($snbox) $newname = GUICtrlRead($namebox) _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.Put ("givenName", $newfn) $ObjUser.Put ("sn", $newsn) $ObjUser.Put ("displayName", $newname) $ObjUser.SetInfo () _AD_Close() MsgBox(0,"","Name information updated successfully") UpdateUserName() Case $msg = $passbutton $newpass = GUICtrlRead($passbox) _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.SetPassword ($newpass) $ObjUser.Put ("pwdLastSet", 0) $ObjUser.SetInfo () _AD_Close() MsgBox(0, "", "Password reset to " & $newpass) UpdateUserName() Case $msg = $descbutton $newdesc = GUICtrlRead($descbox) _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.PutEx ($ADS_PROPERTY_UPDATE, "description", _ArrayCreate($newdesc)) $ObjUser.SetInfo () _AD_Close() MsgBox(0,"","Description updated successfully") UpdateUserName() Case $msg = $homebutton $homedir = GUICtrlRead($homedirbox) Run("explorer.exe /n," & $homedir) UpdateUserName() Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $listselect GetObjectClass() EndSelect WEnd EndFunc+ Edited September 29, 2010 by darkleton Link to comment Share on other sites More sharing options...
wakillon Posted September 29, 2010 Share Posted September 29, 2010 Is it compatible Xp, because nothing happens !A gui with a button in the middle, that's all ... AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
darkleton Posted September 29, 2010 Author Share Posted September 29, 2010 Is it compatible Xp, because nothing happens !A gui with a button in the middle, that's all ...it's an active directory script, so needs to be run on a windows domain (preferably as a domain admin). it runs on xp, but you have to be joined to the domain for it to pick up the usernames Link to comment Share on other sites More sharing options...
water Posted September 29, 2010 Share Posted September 29, 2010 The problem is with the structure of your code.You have two loops where you interpret the user input. GUIGetMsg on line 36 and on line 157.You have recursion in your code. Function UpdateuserName is calling Updateusername which is calling UpdateUsername ....That's why you are in trouble I think you should rewrite your code to get everything done in one loop and without recursion. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
darkleton Posted September 29, 2010 Author Share Posted September 29, 2010 The problem is with the structure of your code.You have two loops where you interpret the user input. GUIGetMsg on line 36 and on line 157.You have recursion in your code. Function UpdateuserName is calling Updateusername which is calling UpdateUsername ....That's why you are in trouble I think you should rewrite your code to get everything done in one loop and without recursion.i think i should rewrite too how will i do the username bit? as i need it to select a username, then let you select any of the buttons, but also let you select another username and do the same?thanks for the hints Link to comment Share on other sites More sharing options...
wakillon Posted September 29, 2010 Share Posted September 29, 2010 it's an active directory script, so needs to be run on a windows domain (preferably as a domain admin). it runs on xp, but you have to be joined to the domain for it to pick up the usernamesAh ok, thanks for the clarification ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
water Posted September 29, 2010 Share Posted September 29, 2010 Wait a bit. I will post a rearranged script in a few minutes ... My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
darkleton Posted September 29, 2010 Author Share Posted September 29, 2010 (edited) ok i think i have it working now after rewriting (and having just seen waters comment!! ) I'm not sure if this is cleaner code, but it does the job for now. are there any more errors in here than the first or is this better laid out? Thanks for the advice water expandcollapse popup#include <GuiListBox.au3> #include <ListBoxConstants.au3> #Include <GUIConstants.au3> #Include <GuiListView.au3> #include <WindowsConstants.au3> #include <ad.au3> #include <Constants.au3> #Include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <array.au3> Const $ouIdentifier = "OU=" Const $cnIdentifier = "CN=" Const $ouSeparator = "\" Const $ADS_PROPERTY_UPDATE = 2 Dim $listmenu, $listselect Dim $userlabel, $userinput, $fnlabel, $snlabel, $fnbox, $snbox Dim $namebox, $namelabel, $namebutton Dim $passbutton, $desclabel, $descbox, $descbutton, $homedirlabel Dim $homedirbox, $homebutton Global $ObjUser, $ObjComp, $msg ;;;;;;;;;;;;; ;insert authentication box code here ;;;;;;;;;;;; Global $gui = GUICreate("OU Browser",570,600) Global $listmenu = GUICtrlCreateList("", 5, 5, 295, 595) Global $listselect = GUICtrlCreateButton(">",305,240,25) GUISetBkColor("0xA0A0A0") $currobjclass = "" Main() Wait() Func Main() UpdateList() GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $listselect DeleteUserBoxes() UpdateUserInfo() ExitLoop EndSelect WEnd EndFunc Func Wait() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $listselect DeleteUserBoxes() UpdateUserInfo() Case $msg = $namebutton NameButton() Case $msg = $passbutton PassButton() Case $msg = $descbutton DescButton() Case $msg = $homebutton HomeButton() EndSelect WEnd EndFunc Func UpdateList() GUICtrlSetData($listmenu,"") GUICtrlSetData($listmenu,"Updating list....please wait") _AD_Open() $arList = _AD_GetObjectsInOU("", "(&(objectclass=user)(objectCategory=person))", "", "sAMAccountName", "sAMAccountName") _AD_Close() GUICtrlSetData($listmenu, "|" & _ArrayToString($arList, "|", 1)) EndFunc Func DeleteUserBoxes() GUICtrlDelete($userlabel) GUICtrlDelete($userinput) GUICtrlDelete($fnlabel) GUICtrlDelete($snlabel) GUICtrlDelete($fnbox) GUICtrlDelete($snbox) GUICtrlDelete($namebox) GUICtrlDelete($namelabel) GUICtrlDelete($namebutton) GUICtrlDelete($passbutton) GUICtrlDelete($desclabel) GUICtrlDelete($descbox) GUICtrlDelete($descbutton) GUICtrlDelete($homedirlabel) GUICtrlDelete($homedirbox) GUICtrlDelete($homebutton) EndFunc Func UpdateUserInfo() _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) _AD_Close() $userlabel = GUICtrlCreateLabel("Username: ", 345, 25, 120, 25) $userinput = GUICtrlCreateInput($username,345,45,207,20,0x0800) $fnlabel = GUICtrlCreateLabel("First Name: ", 345, 80, 120, 25) $snlabel = GUICtrlCreateLabel("Surname: ", 460, 80, 120, 25) $fnbox = GUICtrlCreateInput($objUser.givenName, 345, 100,90,20) $snbox = GUICtrlCreateInput($objUser.sn, 460, 100, 90, 20) $namelabel = GUICtrlCreateLabel("Display Name: ",345, 130,120,25) $namebox = GUICtrlCreateInput($objUser.displayName, 345, 150, 150, 20) Global $namebutton = GUICtrlCreateButton("Update name details",345,175,120,20) Global $passbutton = GUICtrlCreateButton("Reset password",390,237,100,30) $desclabel = GUICtrlCreateLabel("Description: ", 345, 309, 120, 25) $descbox = GUICtrlCreateInput($objUser.description, 345,329,207,20) Global $descbutton = GUICtrlCreateButton("Update Description",345,354,120,20) $homedirlabel = GUICtrlCreateLabel("Home Directory: ", 345, 400, 120, 25) $homedirbox = GUICtrlCreateInput ($objUser.homeDirectory, 345,420,207,20,0x0800) Global $homebutton = GUICtrlCreateButton("Open Home Directory",345,445,120,20) GUICtrlSetFont($userlabel, Default, 600) GUICtrlSetFont($fnlabel, Default, 600) GUICtrlSetFont($snlabel, Default, 600) GUICtrlSetFont($namelabel, Default, 600) GUICtrlSetFont($desclabel, Default, 600) GUICtrlSetFont($homedirlabel, Default, 600) EndFunc Func NameButton() $newfn = GUICtrlRead($fnbox) $newsn = GUICtrlRead($snbox) $newname = GUICtrlRead($namebox) _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.Put ("givenName", $newfn) $ObjUser.Put ("sn", $newsn) $ObjUser.Put ("displayName", $newname) $ObjUser.SetInfo () _AD_Close() MsgBox(0,"","Name information updated successfully") EndFunc Func PassButton() _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.SetPassword ("password") $ObjUser.Put ("pwdLastSet", 0) $ObjUser.SetInfo () _AD_Close() MsgBox(0, "", "Password reset to password") EndFunc Func DescButton() $newdesc = GUICtrlRead($descbox) _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.PutEx ($ADS_PROPERTY_UPDATE, "description", _ArrayCreate($newdesc)) $ObjUser.SetInfo () _AD_Close() MsgBox(0,"","Description updated successfully") EndFunc Func HomeButton() $homedir = GUICtrlRead($homedirbox) Run("explorer.exe /n," & $homedir) EndFunc Edited September 29, 2010 by darkleton Link to comment Share on other sites More sharing options...
water Posted September 29, 2010 Share Posted September 29, 2010 (edited) sorry, took me a few minutes more I've changed the code so you now can enter the part of the ad you want to see. Enter a string and click on one of the buttons and the listview displays the users starting with the specified string. If you just press enter the whole AD is displayed. expandcollapse popup#include <ad.au3> #include <GUIConstants.au3> Const $ouIdentifier = "OU=" Const $cnIdentifier = "CN=" Const $ouSeparator = "\" Const $ADS_PROPERTY_UPDATE = 2 Dim $listmenu, $treemenu, $listselect Dim $passlabel, $passbox Dim $logonlabel, $logonbutton, $logonbox Dim $accntstatuslabel, $accntdisablebox, $accntstatusbutton Dim $ObjUser, $ObjComp, $homebutton, $username, $search Global $gui = GUICreate("OU Browser", 570, 700) Global $searchbox = GUICtrlCreateInput($search, 5, 10, 295, 20) Global $searchsambutton = GUICtrlCreateButton("Search SamAccount", 5, 50, 130) Global $searchnamebutton = GUICtrlCreateButton("Search Name", 170, 50, 130) Global $listmenu = GUICtrlCreateList("", 5, 105, 295, 595) Global $listselect = GUICtrlCreateButton(">", 305, 340, 25) Global $userlabel = GUICtrlCreateLabel("Username: ", 345, 125, 120, 25) Global $userinput = GUICtrlCreateInput($username, 345, 145, 207, 20, 0x0800) Global $fnlabel = GUICtrlCreateLabel("First Name: ", 345, 180, 120, 25) Global $snlabel = GUICtrlCreateLabel("Surname: ", 460, 180, 120, 25) Global $fnbox = GUICtrlCreateInput("", 345, 200, 90, 20) Global $snbox = GUICtrlCreateInput("", 460, 200, 90, 20) Global $namelabel = GUICtrlCreateLabel("Display Name: ", 345, 230, 120, 25) Global $namebox = GUICtrlCreateInput("", 345, 250, 150, 20) Global $namebutton = GUICtrlCreateButton("Update name details", 345, 275, 120, 20) Global $passbutton = GUICtrlCreateButton("Reset password", 390, 337, 100, 30) Global $desclabel = GUICtrlCreateLabel("Description: ", 345, 409, 120, 25) Global $descbox = GUICtrlCreateInput("", 345, 429, 207, 20) Global $descbutton = GUICtrlCreateButton("Update Description", 345, 454, 120, 20) Global $homedirlabel = GUICtrlCreateLabel("Home Directory: ", 345, 500, 120, 25) Global $homedirbox = GUICtrlCreateInput("", 345, 520, 207, 20, 0x0800) Global $homebutton = GUICtrlCreateButton("Open Home Directory", 345, 545, 120, 20) GUICtrlSetFont($userlabel, Default, 600) GUICtrlSetFont($fnlabel, Default, 600) GUICtrlSetFont($snlabel, Default, 600) GUICtrlSetFont($namelabel, Default, 600) GUICtrlSetFont($passlabel, Default, 600) GUICtrlSetFont($desclabel, Default, 600) GUICtrlSetFont($homedirlabel, Default, 600) GUICtrlSetFont($logonlabel, Default, 600) GUICtrlSetFont($accntstatuslabel, Default, 600) GUISetBkColor("0xA0A0A0") GUICtrlSetData($listmenu, "") ;GUICtrlSetData($listmenu, "Updating list....please wait") GUISetState() While 1 $msg = GUIGetMsg() Select ; Case $msg = "" ; In case the other buttons have no value (= "") Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $searchsambutton Or $msg = $searchnamebutton $search = GUICtrlRead($searchbox) _AD_Open() ConsoleWrite($search & @CRLF) If $msg = $searchsambutton Then $search = "(samaccountname=" & $search & "*)" Else $search = "(name=" & $search & "*)" Endif $arList = _AD_GetObjectsInOU("", "(&(objectclass=user)(objectCategory=person)" & $search & ")", "", "sAMAccountName", "sAMAccountName") GUICtrlSetData($listmenu, "|" & _ArrayToString($arList, "|", 1)) _AD_Close() Case $msg = $listselect GetObjectClass() Case $msg = $namebutton $newfn = GUICtrlRead($fnbox) $newsn = GUICtrlRead($snbox) $newname = GUICtrlRead($namebox) _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.Put("givenName", $newfn) $ObjUser.Put("sn", $newsn) $ObjUser.Put("displayName", $newname) $ObjUser.SetInfo() _AD_Close() MsgBox(0, "", "Name information updated successfully") Case $msg = $passbutton $newpass = GUICtrlRead($passbox) _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.SetPassword($newpass) $ObjUser.Put("pwdLastSet", 0) $ObjUser.SetInfo() _AD_Close() MsgBox(0, "", "Password reset to " & $newpass) Case $msg = $descbutton $newdesc = GUICtrlRead($descbox) _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.PutEx($ADS_PROPERTY_UPDATE, "description", _ArrayCreate($newdesc)) $ObjUser.SetInfo() _AD_Close() MsgBox(0, "", "Description updated successfully") Case $msg = $homebutton $homedir = GUICtrlRead($homedirbox) Run("explorer.exe /n," & $homedir) EndSelect WEnd Func GetObjectClass() $listselection = GUICtrlRead($listmenu, 1) _AD_Open() $listclass = _AD_GetObjectClass($listselection) _AD_Close() If $listclass = "user" Then UpdateUserInfo() EndFunc ;==>GetObjectClass Func UpdateUserInfo() _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) _AD_Close() GUICtrlSetData($fnbox, $ObjUser.givenName) GUICtrlSetData($snbox ,$ObjUser.sn) GUICtrlSetData($namebox, $ObjUser.displayName) GUICtrlSetData($descbox, $ObjUser.description) GUICtrlSetData($homedirbox, $ObjUser.homeDirectory) EndFunc ;==>UpdateUserInfo Func UpdateComputerInfo() _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $pcfqdn = _AD_SamAccountNameToFQDN($listselection) $pcname = _AD_FQDNToSamAccountName($pcfqdn) $ObjComp = ObjGet("LDAP://" & $pcfqdn) $objCompStatus = $ObjComp.AccountDisabled MsgBox(0, "", "computer status is " & $objCompStatus) _AD_Close() EndFunc ;==>UpdateComputerInfo Edited September 29, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
darkleton Posted September 29, 2010 Author Share Posted September 29, 2010 wow, that search bit is just the icing on the cake thank you so much Link to comment Share on other sites More sharing options...
darkleton Posted September 29, 2010 Author Share Posted September 29, 2010 I just noticed that the username field isn't entered anymore. It does the following to get the username (and worked on my old script) so i assume that with the new way of searching it isn't doing it right? _AD_Open() $listselection = GUICtrlRead($listmenu, 1) $userfqdn = _AD_SamAccountNameToFQDN($listselection) $username = _AD_FQDNToSamAccountName($userfqdn) $ObjUser = ObjGet("LDAP://" & $userfqdn) _AD_Close() thanks Link to comment Share on other sites More sharing options...
water Posted September 29, 2010 Share Posted September 29, 2010 New version. Removed bug and changed list to listview. expandcollapse popup#include <ad.au3> #include <GUIConstants.au3> #Include <GuiListView.au3> Const $ouIdentifier = "OU=" Const $cnIdentifier = "CN=" Const $ouSeparator = "\" Const $ADS_PROPERTY_UPDATE = 2 Dim $listmenu, $treemenu, $listselect, $listselection Dim $passlabel, $passbox Dim $logonlabel, $logonbutton, $logonbox Dim $accntstatuslabel, $accntdisablebox, $accntstatusbutton Dim $ObjUser, $ObjComp, $homebutton, $search Global $gui = GUICreate("OU Browser", 570, 700) Global $searchbox = GUICtrlCreateInput($search, 5, 10, 295, 20) Global $searchsambutton = GUICtrlCreateButton("Search Username", 5, 50, 130) Global $searchnamebutton = GUICtrlCreateButton("Search Name", 170, 50, 130) Global $listmenu = GUICtrlCreateListView("Username|DisplayName", 5, 105, 295, 595) Global $listselect = GUICtrlCreateButton(">", 305, 340, 25) Global $userlabel = GUICtrlCreateLabel("Username: ", 345, 125, 120, 25) Global $userinput = GUICtrlCreateInput("", 345, 145, 207, 20, 0x0800) Global $fnlabel = GUICtrlCreateLabel("First Name: ", 345, 180, 120, 25) Global $snlabel = GUICtrlCreateLabel("Surname: ", 460, 180, 120, 25) Global $fnbox = GUICtrlCreateInput("", 345, 200, 90, 20) Global $snbox = GUICtrlCreateInput("", 460, 200, 90, 20) Global $namelabel = GUICtrlCreateLabel("Display Name: ", 345, 230, 120, 25) Global $namebox = GUICtrlCreateInput("", 345, 250, 150, 20) Global $namebutton = GUICtrlCreateButton("Update name details", 345, 275, 120, 20) Global $passbutton = GUICtrlCreateButton("Reset password", 390, 337, 100, 30) Global $desclabel = GUICtrlCreateLabel("Description: ", 345, 409, 120, 25) Global $descbox = GUICtrlCreateInput("", 345, 429, 207, 20) Global $descbutton = GUICtrlCreateButton("Update Description", 345, 454, 120, 20) Global $homedirlabel = GUICtrlCreateLabel("Home Directory: ", 345, 500, 120, 25) Global $homedirbox = GUICtrlCreateInput("", 345, 520, 207, 20, 0x0800) Global $homebutton = GUICtrlCreateButton("Open Home Directory", 345, 545, 120, 20) GUICtrlSetFont($userlabel, Default, 600) GUICtrlSetFont($fnlabel, Default, 600) GUICtrlSetFont($snlabel, Default, 600) GUICtrlSetFont($namelabel, Default, 600) GUICtrlSetFont($passlabel, Default, 600) GUICtrlSetFont($desclabel, Default, 600) GUICtrlSetFont($homedirlabel, Default, 600) GUICtrlSetFont($logonlabel, Default, 600) GUICtrlSetFont($accntstatuslabel, Default, 600) GUISetBkColor("0xA0A0A0") GUICtrlSetData($listmenu, "") GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = "" Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $searchsambutton Or $msg = $searchnamebutton $search = GUICtrlRead($searchbox) _AD_Open() If $msg = $searchsambutton Then $search = "(samaccountname=" & $search & "*)" Else $search = "(name=" & $search & "*)" EndIf $arList = _AD_GetObjectsInOU("", "(&(objectclass=user)(objectCategory=person)" & $search & ")", "", "sAMAccountName,displayname", "sAMAccountName") _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listmenu)) For $iIndex1 = 1 To $arList[0][0] $Tmp = "" For $iIndex2 = 0 To $arList[0][1]-1 $Tmp &= $arList[$iIndex1][$iIndex2] & "|" Next GUICtrlCreateListViewItem($Tmp, $listmenu) Next _AD_Close() Case $msg = $listselect GetObjectClass() Case $msg = $namebutton $newfn = GUICtrlRead($fnbox) $newsn = GUICtrlRead($snbox) $newname = GUICtrlRead($namebox) _AD_Open() $userfqdn = _AD_SamAccountNameToFQDN($listselection) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.Put("givenName", $newfn) $ObjUser.Put("sn", $newsn) $ObjUser.Put("displayName", $newname) $ObjUser.SetInfo() _AD_Close() MsgBox(0, "", "Name information updated successfully") Case $msg = $passbutton $newpass = GUICtrlRead($passbox) _AD_Open() $userfqdn = _AD_SamAccountNameToFQDN($listselection) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.SetPassword($newpass) $ObjUser.Put("pwdLastSet", 0) $ObjUser.SetInfo() _AD_Close() MsgBox(0, "", "Password reset to " & $newpass) Case $msg = $descbutton $newdesc = GUICtrlRead($descbox) _AD_Open() $userfqdn = _AD_SamAccountNameToFQDN($listselection) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.PutEx($ADS_PROPERTY_UPDATE, "description", _ArrayCreate($newdesc)) $ObjUser.SetInfo() _AD_Close() MsgBox(0, "", "Description updated successfully") Case $msg = $homebutton $homedir = GUICtrlRead($homedirbox) Run("explorer.exe /n," & $homedir) EndSelect WEnd Func GetObjectClass() $listselection = $arList[_GUICtrlListView_GetSelectedIndices($listmenu)+1][0] _AD_Open() $listclass = _AD_GetObjectClass($listselection) _AD_Close() If $listclass = "user" Then UpdateUserInfo() EndFunc ;==>GetObjectClass Func UpdateUserInfo() _AD_Open() $userfqdn = _AD_SamAccountNameToFQDN($listselection) $ObjUser = ObjGet("LDAP://" & $userfqdn) _AD_Close() GUICtrlSetData($userinput, $listselection) GUICtrlSetData($fnbox, $ObjUser.givenName) GUICtrlSetData($snbox, $ObjUser.sn) GUICtrlSetData($namebox, $ObjUser.displayName) GUICtrlSetData($descbox, $ObjUser.description) GUICtrlSetData($homedirbox, $ObjUser.homeDirectory) EndFunc ;==>UpdateUserInfo Func UpdateComputerInfo() _AD_Open() $pcfqdn = _AD_SamAccountNameToFQDN($listselection) $pcname = _AD_FQDNToSamAccountName($pcfqdn) $ObjComp = ObjGet("LDAP://" & $pcfqdn) $objCompStatus = $ObjComp.AccountDisabled MsgBox(0, "", "computer status is " & $objCompStatus) _AD_Close() EndFunc ;==>UpdateComputerInfo My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
darkleton Posted September 29, 2010 Author Share Posted September 29, 2010 (edited) i know you're going to hate me..... when i originally done the script i made the buttons be drawn after a user was selected. as your one draws them first, if, for example, the update user info button is clicked before a user is selected it fails with a com error (as no objuser is there). is there any way of having the buttons drawn as a user is selected, and then deleted after (as i had probs with it rewriting a button over a button). or should i just set the buttons as disabled and when the first user is selected set them to enabled? **EDIT** i just set the buttons to $WS_DISABLED and then at the end of the updateuserinfo() it enables them with guictrlsetstate. that appears to do the job. thanks for all your help water Edited September 29, 2010 by darkleton Link to comment Share on other sites More sharing options...
water Posted September 29, 2010 Share Posted September 29, 2010 (edited) I now test if a user has been selected. If not, nothing happens: expandcollapse popup#include <ad.au3> #include <GUIConstants.au3> #Include <GuiListView.au3> Const $ouIdentifier = "OU=" Const $cnIdentifier = "CN=" Const $ouSeparator = "\" Const $ADS_PROPERTY_UPDATE = 2 Dim $listmenu, $treemenu, $listselect, $listselection Dim $passlabel, $passbox Dim $logonlabel, $logonbutton, $logonbox Dim $accntstatuslabel, $accntdisablebox, $accntstatusbutton Dim $ObjUser, $ObjComp, $homebutton, $search Global $gui = GUICreate("OU Browser", 570, 700) Global $searchbox = GUICtrlCreateInput($search, 5, 10, 295, 20) Global $searchsambutton = GUICtrlCreateButton("Search Username", 5, 50, 130) Global $searchnamebutton = GUICtrlCreateButton("Search Displayname", 170, 50, 130) Global $listmenu = GUICtrlCreateListView("Username|DisplayName", 5, 105, 295, 595) Global $listselect = GUICtrlCreateButton(">", 305, 340, 25) Global $userlabel = GUICtrlCreateLabel("Username: ", 345, 125, 120, 25) Global $userinput = GUICtrlCreateInput("", 345, 145, 207, 20, 0x0800) Global $fnlabel = GUICtrlCreateLabel("First Name: ", 345, 180, 120, 25) Global $snlabel = GUICtrlCreateLabel("Surname: ", 460, 180, 120, 25) Global $fnbox = GUICtrlCreateInput("", 345, 200, 90, 20) Global $snbox = GUICtrlCreateInput("", 460, 200, 90, 20) Global $namelabel = GUICtrlCreateLabel("Display Name: ", 345, 230, 120, 25) Global $namebox = GUICtrlCreateInput("", 345, 250, 150, 20) Global $namebutton = GUICtrlCreateButton("Update name details", 345, 275, 120, 20) Global $passbutton = GUICtrlCreateButton("Reset password", 390, 337, 100, 30) Global $desclabel = GUICtrlCreateLabel("Description: ", 345, 409, 120, 25) Global $descbox = GUICtrlCreateInput("", 345, 429, 207, 20) Global $descbutton = GUICtrlCreateButton("Update Description", 345, 454, 120, 20) Global $homedirlabel = GUICtrlCreateLabel("Home Directory: ", 345, 500, 120, 25) Global $homedirbox = GUICtrlCreateInput("", 345, 520, 207, 20, 0x0800) Global $homebutton = GUICtrlCreateButton("Open Home Directory", 345, 545, 120, 20) GUICtrlSetFont($userlabel, Default, 600) GUICtrlSetFont($fnlabel, Default, 600) GUICtrlSetFont($snlabel, Default, 600) GUICtrlSetFont($namelabel, Default, 600) GUICtrlSetFont($passlabel, Default, 600) GUICtrlSetFont($desclabel, Default, 600) GUICtrlSetFont($homedirlabel, Default, 600) GUICtrlSetFont($logonlabel, Default, 600) GUICtrlSetFont($accntstatuslabel, Default, 600) GUISetBkColor("0xA0A0A0") GUICtrlSetData($listmenu, "") GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = "" Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $searchsambutton Or $msg = $searchnamebutton $search = GUICtrlRead($searchbox) _AD_Open() If $msg = $searchsambutton Then $search = "(samaccountname=" & $search & "*)" Else $search = "(name=" & $search & "*)" EndIf $arList = _AD_GetObjectsInOU("", "(&(objectclass=user)(objectCategory=person)" & $search & ")", "", "sAMAccountName,displayname", "sAMAccountName") _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listmenu)) For $iIndex1 = 1 To $arList[0][0] $Tmp = "" For $iIndex2 = 0 To $arList[0][1]-1 $Tmp &= $arList[$iIndex1][$iIndex2] & "|" Next GUICtrlCreateListViewItem($Tmp, $listmenu) Next _AD_Close() Case $msg = $listselect GetObjectClass() Case $msg = $namebutton If $listselection = "" Then ContinueCase $newfn = GUICtrlRead($fnbox) $newsn = GUICtrlRead($snbox) $newname = GUICtrlRead($namebox) _AD_Open() $userfqdn = _AD_SamAccountNameToFQDN($listselection) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.Put("givenName", $newfn) $ObjUser.Put("sn", $newsn) $ObjUser.Put("displayName", $newname) $ObjUser.SetInfo() _AD_Close() MsgBox(0, "", "Name information updated successfully") Case $msg = $passbutton If $listselection = "" Then ContinueCase $newpass = GUICtrlRead($passbox) _AD_Open() $userfqdn = _AD_SamAccountNameToFQDN($listselection) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.SetPassword($newpass) $ObjUser.Put("pwdLastSet", 0) $ObjUser.SetInfo() _AD_Close() MsgBox(0, "", "Password reset to " & $newpass) Case $msg = $descbutton If $listselection = "" Then ContinueCase $newdesc = GUICtrlRead($descbox) _AD_Open() $userfqdn = _AD_SamAccountNameToFQDN($listselection) $ObjUser = ObjGet("LDAP://" & $userfqdn) $ObjUser.PutEx($ADS_PROPERTY_UPDATE, "description", _ArrayCreate($newdesc)) $ObjUser.SetInfo() _AD_Close() MsgBox(0, "", "Description updated successfully") Case $msg = $homebutton If $listselection = "" Then ContinueCase $homedir = GUICtrlRead($homedirbox) Run("explorer.exe /n," & $homedir) Case Else EndSelect WEnd Func GetObjectClass() $listselection = $arList[_GUICtrlListView_GetSelectedIndices($listmenu)+1][0] _AD_Open() $listclass = _AD_GetObjectClass($listselection) _AD_Close() If $listclass = "user" Then UpdateUserInfo() EndFunc ;==>GetObjectClass Func UpdateUserInfo() _AD_Open() $userfqdn = _AD_SamAccountNameToFQDN($listselection) $ObjUser = ObjGet("LDAP://" & $userfqdn) _AD_Close() GUICtrlSetData($userinput, $listselection) GUICtrlSetData($fnbox, $ObjUser.givenName) GUICtrlSetData($snbox, $ObjUser.sn) GUICtrlSetData($namebox, $ObjUser.displayName) GUICtrlSetData($descbox, $ObjUser.description) GUICtrlSetData($homedirbox, $ObjUser.homeDirectory) EndFunc ;==>UpdateUserInfo Func UpdateComputerInfo() _AD_Open() $pcfqdn = _AD_SamAccountNameToFQDN($listselection) $pcname = _AD_FQDNToSamAccountName($pcfqdn) $ObjComp = ObjGet("LDAP://" & $pcfqdn) $objCompStatus = $ObjComp.AccountDisabled MsgBox(0, "", "computer status is " & $objCompStatus) _AD_Close() EndFunc ;==>UpdateComputerInfo Edited September 29, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now