sublimnl Posted September 21, 2006 Share Posted September 21, 2006 (edited) I'm writing a quick script/GUI to rename computers on the network to make life easier for some of my coworkers. It's completely done now, except for the fact that I cannot close the second GUI that comes up. No matter what I do I cannot seem to get the Exit button, or the X at the top right hand corner to do anything. What am I doing wrong? expandcollapse popup#include <constants.au3> #include <GUIConstants.au3> ;#NoTrayIcon FileInstall("C:\AU3includes\netdom.exe","C:\Windows\netdom.exe",1) Global $checked Global $Button1 Global $ChkBoxMove Global $CmbSite, $CmbType, $confmsg, $InpCurName, $InpNewName, $msg, $skip, $Form2 $checked = 0 GUI() Func GUI() Opt("GUIOnEventMode", 1) ; == GUI generated with Koda == $Form1 = GUICreate("Computer Remame Tool", 323, 291, 279, 243) GUISetIcon("C:\Documents and Settings\*\Desktop\Icons\CHUMS\Universal.ico") $InpCurName = GUICtrlCreateInput("", 104, 53, 193, 21, -1, $WS_EX_CLIENTEDGE) $InpNewName = GUICtrlCreateInput("", 104, 93, 193, 21, -1, $WS_EX_CLIENTEDGE) GUICtrlCreateLabel("Current Name:", 24, 56, 72, 17) GUICtrlCreateLabel("New Name:", 24, 96, 60, 17) $Button1 = GUICtrlCreateButton("DO IT", 120, 251, 89, 27) GUICtrlCreateLabel("Computer Rename Tool", 16, 12, 294, 26) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") $Group1 = GUICtrlCreateGroup("", 36, 141, 273, 97) $CmbSite = GUICtrlCreateCombo("Houston", 98, 168, 194, 21,$CBS_DROPDOWNLIST) $CmbType = GUICtrlCreateCombo("Workstations", 98, 200, 194, 21,$CBS_DROPDOWNLIST) GUICtrlSetData($CmbSite,"Delft|KL|Perth|Rio de Janeiro|UK") GUICtrlSetData($CmbType,"Laptops") GUICtrlSetState($CmbSite,$GUI_DISABLE) GUICtrlSetState($CmbType,$GUI_DISABLE) GUICtrlCreateLabel("Type:", 54, 202, 31, 17) GUICtrlCreateLabel("Site:", 59, 171, 25, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $ChkBoxMove = GUICtrlCreateCheckbox("Move Account", 25, 136, 97, 25) GUICtrlSetOnEvent($ChkBoxMove,"EnaOUMove") GUICtrlSetOnEvent($Button1,"DoIt") GUISetOnEvent($GUI_EVENT_CLOSE,"CGTerm") GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;;;;;; EndSelect If StringStripWS(GUICtrlRead($InpCurName),8) <> "" AND StringStripWS(GUICtrlRead($InpNewName),8) <> "" Then GUICtrlSetState($Button1,$GUI_ENABLE) Else GUICtrlSetState($Button1,$GUI_DISABLE) EndIf Sleep(500) WEnd EndFunc Func EnaOUMove() $checked=GuiCtrlRead($ChkBoxMove) If $checked = 1 Then GUICtrlSetState($CmbSite,$GUI_ENABLE) GUICtrlSetState($CmbType,$GUI_ENABLE) Else GUICtrlSetState($CmbSite,$GUI_DISABLE) GUICtrlSetState($CmbType,$GUI_DISABLE) EndIf EndFunc Func DoIt() GUISetState(@SW_HIDE) $confmsg = "This will rename the computer account " & StringStripWS(GUICtrlRead($InpCurName),8) & " to " & StringStripWS(GUICtrlRead($InpNewName),8) If $checked=1 Then $confmsg = $confmsg & ", and move it to " & GUICtrlRead($CmbSite) & "\" & GUICtrlRead($CmbType) & ". Are you sure you want to proceed?" Else $confmsg = $confmsg & ". Are you sure you want to proceed?" EndIf $continue = MsgBox(292,"Confirm changes",$confmsg) If $continue = 7 Then Exit ExeLog() EndFunc Func ExeLog() Opt("GUIOnEventMode",1) ; == GUI generated with Koda == $Form2 = GUICreate("Results Log", 640, 328, 206, 140) GUISetOnEvent($GUI_EVENT_CLOSE,"CGTerm") GUISetIcon("C:\Documents and Settings\*\Desktop\Icons\CHUMS\Universal.ico") $MemoBox = GUICtrlCreateEdit("", 8, 8,624, 265, $ES_READONLY, $WS_EX_CLIENTEDGE) $BtnExit = GUICtrlCreateButton("Exit", 550, 288, 81, 33) GUICtrlSetOnEvent($BtnExit,"CGTerm") GUISetState(@SW_SHOW) $skip = 0 If $checked = 1 Then GUICtrlSetData($MemoBox,"===================MOVING COMPUTER TO DESTINATION OU===================" & @CRLF & @CRLF) $NewOU='"OU=' & GuiCtrlRead($CmbType) & ',OU=' & GuiCtrlRead($CmbSite) & ',OU=NAME,DC=NAME,DC=com"' ;$cmd = "dsquery computer domainroot -name " & GuiCtrlRead($InpCurName) &" |dsmove -newparent " & $NewOU & " -u domain\user -p password" $cmd = "dsquery computer domainroot -name " & GuiCtrlRead($InpCurName) GUICtrlSetData($MemoBox,"EXECUTING: " & $cmd & @CRLF & @CRLF,Default) $result = Run(@ComSpec & " /c dsquery computer domainroot -name " & GUICtrlRead($InpCurName),@WorkingDir,@SW_HIDE,$STDOUT_CHILD) $result = StringStripWS(StdoutRead($result),3) If $result = "" Then $skip = 1 $result = "Source computer name does not exist in directory!" Else $skip = 0 $result = "Found source at: " & $result EndIf GUICtrlSetData($MemoBox,"CMDRESULT: " & $result & @CRLF & @CRLF,Default) If $skip = 0 Then $result = StringTrimLeft($result,17) $cmd = "dsmove " & $result & " -newparent " & $NewOU & " -u domain\user -p password" GUICtrlSetData($MemoBox,"EXECUTING: " & $cmd & @CRLF & @CRLF,Default) $result = Run(@ComSpec & " /c dsmove " & $result & " -newparent " & $NewOU & " -u domain\user -p password",@WorkingDir,@SW_HIDE,$STDOUT_CHILD) $result = StdoutRead($result) If $result = "" Then $result = "Failed to move computer account to new OU!" GUICtrlSetData($MemoBox,"CMDRESULT: " & $result & @CRLF & @CRLF,Default) EndIf EndIf If $skip = 0 Then GUICtrlSetData($MemoBox,"===========================RENAMING COMPUTER===========================" & @CRLF & @CRLF,Default) $cmd = "netdom renamecomputer " & StringStripWS(GUICtrlRead($InpCurName),8) & " /NewName " & StringStripWS(GUICtrlRead($InpNewName),8) & _ " /UserD:domain\user /PasswordD:password /UserO:domain\user /PasswordO:password /Force" GUICtrlSetData($MemoBox,"EXECUTING: " & $cmd & @CRLF & @CRLF,Default) $result = Run(@ComSpec & " /c netdom renamecomputer " & StringStripWS(GUICtrlRead($InpCurName),8) & " /NewName " & StringStripWS(GUICtrlRead($InpNewName),8) & _ " /UserD:domainuser /PasswordD:password /UserO:domain\user /PasswordO:password /Force",@WindowsDir,@SW_HIDE,$STDOUT_CHILD) $result = StdoutRead($result) GUICtrlSetData($MemoBox,"CMDRESULT: " & $result & @CRLF & @CRLF,Default) EndIf While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;;;;;; EndSelect Sleep(500) WEnd CGTerm() EndFunc Func CGTerm() Exit EndFunc Edited September 21, 2006 by sublimnl Link to comment Share on other sites More sharing options...
MHz Posted September 21, 2006 Share Posted September 21, 2006 Looks like two different Gui Modes at the exact same time being used?If the GUIOnEventMode option is set to 1 then the return from GUIGetMsg is always 0 and the @error is set to 1.If the option GUIEventOptions is set to 1 the minimize, restore and maximize button will not do any action on the window just a simple notification. Link to comment Share on other sites More sharing options...
CWorks Posted September 21, 2006 Share Posted September 21, 2006 to get rid of a gui try GUIDelete($Form1) or GUISetState(@SW_HIDE, $Form1) Link to comment Share on other sites More sharing options...
sublimnl Posted September 21, 2006 Author Share Posted September 21, 2006 Looks like two different Gui Modes at the exact same time being used?Thanks. Got rid of the While loop and that did it! 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