XmangiaX Posted February 7, 2006 Share Posted February 7, 2006 Hello. I recently found AutoIt v3 and cant say enough good things about it. Thanks. To my issue.... I am fairly new to scripting and Ive searched for restarting my 2003 servers via script. What I have come up with is this: Run("cmd.exe") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send("shutdown -r -t 01 -m \\servername") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send ("{ENTER}") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send("Exit") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send ("{ENTER}") What I would rather have my script do is open a gui and list my servers numbered 1-whatever. I want an option to select a number correlating to a server, then a confirmation box asking "yes" or "no" to restarting the server. If this topic has been covered, I apologize for not finding it. Im not asking for a script to be written, just some direction would be nice. Thanks for any help given in advance. Link to comment Share on other sites More sharing options...
flaxcrack Posted February 7, 2006 Share Posted February 7, 2006 Hello. I recently found AutoIt v3 and cant say enough good things about it. Thanks. To my issue.... I am fairly new to scripting and Ive searched for restarting my 2003 servers via script. What I have come up with is this: Run("cmd.exe") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send("shutdown -r -t 01 -m \\servername") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send ("{ENTER}") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send("Exit") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send ("{ENTER}") What I would rather have my script do is open a gui and list my servers numbered 1-whatever. I want an option to select a number correlating to a server, then a confirmation box asking "yes" or "no" to restarting the server. If this topic has been covered, I apologize for not finding it. Im not asking for a script to be written, just some direction would be nice. Thanks for any help given in advance. click start, run, type: shutdown -i [quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD() Link to comment Share on other sites More sharing options...
XmangiaX Posted February 7, 2006 Author Share Posted February 7, 2006 Im actually wanting a gui to shutdown my servers. so far I have: ;Script for shutting down specific server ; GUI GuiCreate("Server Shutdown", 400, 400) $filemenu = GuiCtrlCreateMenu ("File") $trackmenu = GuiCtrlCreateContextMenu () $aboutitem = GuiCtrlCreateMenuitem ("About",$trackmenu) $exititem = GuiCtrlCreateMenuitem ("Exit",$filemenu) GuiCtrlCreateMenuitem ("",$trackmenu) $exititem = GuiCtrlCreateMenuitem ("Exit",$trackmenu) $GuiCtrlCreateButton = GuiCtrlCreateButton ("server1",10, 170, 75, 25) $GuiCtrlCreateButton = GuiCtrlCreateButton ("server2",100, 170, 75, 25) $GuiCtrlCreateButton = GuiCtrlCreateButton ("server3",190, 170, 75, 25) GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $filemenu ExitLoop If $msg = $exititem Or $msg = -3 Or $msg = -1 Then ExitLoop If $msg = $aboutitem Then Msgbox(0,"About","A simple example with a context menu!") Case $msg = $exititem ExitLoop EndSelect WEnd When I select a specific button I want it to restart that specific server. Does that make sense? Im very new to this Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted February 7, 2006 Moderators Share Posted February 7, 2006 (edited) You could try something like this: #include <GUIConstants.au3> ;Script for shutting down specific server Dim $server1 = "Server1";name of server 1 Dim $server2 = "Server2";name of server 2 Dim $server3 = "Server3";name of server 3 Dim $time = "20";seconds to delay shutdown ; GUI GUICreate("Server Shutdown", 200, 100) $s1 = GUICtrlCreateButton($server1, 10, 40) $s2 = GUICtrlCreateButton($server2, 75, 40) $s3 = GUICtrlCreateButton($server3, 140, 40) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $s1 Run(@ComSpec & " /c " & "shutdown -s -m \\" & $server1 & " -t " & $time) Case $msg = $s2 Run(@ComSpec & " /c " & "shutdown -s -m \\" & $server2 & " -t " & $time) Case $msg = $s3 Run(@ComSpec & " /c " & "shutdown -s -m \\" & $server3 & " -t " & $time) EndSelect WEnd Edit: Forgot a space between @ComSpec and /c Edited February 7, 2006 by big_daddy Link to comment Share on other sites More sharing options...
XmangiaX Posted February 7, 2006 Author Share Posted February 7, 2006 (edited) Thanks, This is exactly what I am looking for. I will replace the server names with my real server names and give this a shot. Big Daddy thanks a million!! I have a 2nd part question which may make this script more complicated. :"> When I select "server1" is it possible to have a new window pop up and ask me to either "shutdown" "reboot" or "cancel" with the server name in the window? And then do the task I want in the background. I dont really want the cmd.exe window to pop up. When I select "server button" from the main menu, id like to have a new window with the 3 options of "shutdown" "reboot" and "cancel" pop up. And when I select a specific function it will do it in the backgorund. I hope that make sense. its been a long day for this noob I will now add the remaining 22 servers I have into this script Big Daddy created. Once again thanks to all who have assisted me in this adventure. Ive learned alot today! UPDATE: I solved my server name issue Edited February 7, 2006 by XmangiaX Link to comment Share on other sites More sharing options...
flaxcrack Posted February 7, 2006 Share Posted February 7, 2006 Right! You can't have the '-' in your varable name. Hence Dim $FHA-DR-5 can't be used... Try Dim $FHADR5 as the var name it will work. [quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD() Link to comment Share on other sites More sharing options...
XmangiaX Posted February 7, 2006 Author Share Posted February 7, 2006 (edited) Right! You can't have the '-' in your varable name.Hence Dim $FHA-DR-5 can't be used... Try Dim $FHADR5 as the var name it will work.Thats exactly what I did. Im at the end of my day and my brain is FRIED! Thanks flax!Scripting is a new beast for me and I think I have grasped a few new concepts today. Looking through Big Daddys script makes sense to me now. I just need a few more options to go along with what I have and Ill be set. When I select "server button" from the main menu, id like to have a new window with the 3 options of "shutdown" "reboot" and "cancel" pop up. And when I select a specific function it will do it in the backgorund.Thanks everyone Edited February 7, 2006 by XmangiaX Link to comment Share on other sites More sharing options...
skippynz Posted February 7, 2006 Share Posted February 7, 2006 Thats exactly what I did. Im at the end of my day and my brain is FRIED! Thanks flax! Scripting is a new beast for me and I think I have grasped a few new concepts today. Looking through Big Daddys script makes sense to me now. I just need a few more options to go along with what I have and Ill be set. Thanks everyone i just had a play and came up with the following if ya want it. - it has checkboxes for the servers you want to reboot, and radio button to select restart or shutdown. functions at the end could possibly be done a different way, but im still learning to script myself. expandcollapse popup#include <GuiConstants.au3> If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 GuiCreate("Restart the following machines", 110, 260) $Checkbox_1 = GuiCtrlCreateCheckbox("Server 1", 25, 10, 90, 20);3 $Checkbox_2 = GuiCtrlCreateCheckbox("Server 2", 25, 30, 90, 20);4 $Checkbox_3 = GuiCtrlCreateCheckbox("Server 3", 25, 50, 90, 20);5 $Checkbox_4 = GuiCtrlCreateCheckbox("Server 4", 25, 70, 90, 20);6 $Checkbox_5 = GuiCtrlCreateCheckbox("Server 5", 25, 90, 90, 20);7 $Checkbox_6 = GuiCtrlCreateCheckbox("Server 6", 25, 110, 90, 20);8 $Checkbox_7 = GuiCtrlCreateCheckbox("Server 7", 25, 130, 90, 20);9 $Radio_8 = GuiCtrlCreateRadio("Restart", 25, 170, 90, 20);10 $Radio_9 = GuiCtrlCreateRadio("Shutdown", 25, 190, 90, 20);11 $Button_1 = GuiCtrlCreateButton("OK", 10, 230, 90, 20);12 GUICtrlSetState(10,$GUI_CHECKED) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 server_1() server_2() server_3() server_4() server_5() server_6() server_7() EndSelect WEnd Exit Func server_1() If GUICtrlRead($Checkbox_1) = $GUI_CHECKED Then if GUICtrlRead($Radio_8) = $GUI_CHECKED Then ; restart Else ; shutdown EndIf Else EndIf EndFunc Func server_2() If GUICtrlRead($Checkbox_2) = $GUI_CHECKED Then if GUICtrlRead($Radio_8) = $GUI_CHECKED Then ; restart Else ; shutdown EndIf Else EndIf EndFunc Func server_3() If GUICtrlRead($Checkbox_3) = $GUI_CHECKED Then if GUICtrlRead($Radio_8) = $GUI_CHECKED Then ; restart Else ; shutdown EndIf Else EndIf EndFunc Func server_4() If GUICtrlRead($Checkbox_4) = $GUI_CHECKED Then if GUICtrlRead($Radio_8) = $GUI_CHECKED Then ; restart Else ; shutdown EndIf Else EndIf EndFunc Func server_5() If GUICtrlRead($Checkbox_5) = $GUI_CHECKED Then if GUICtrlRead($Radio_8) = $GUI_CHECKED Then ; restart Else ; shutdown EndIf Else EndIf EndFunc Func server_6() If GUICtrlRead($Checkbox_6) = $GUI_CHECKED Then if GUICtrlRead($Radio_8) = $GUI_CHECKED Then ; restart Else ; shutdown EndIf Else EndIf EndFunc Func server_7() If GUICtrlRead($Checkbox_7) = $GUI_CHECKED Then if GUICtrlRead($Radio_8) = $GUI_CHECKED Then ; restart Else ; shutdown EndIf Else EndIf EndFunc Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted February 7, 2006 Moderators Share Posted February 7, 2006 Thanks, This is exactly what I am looking for. I will replace the server names with my real server names and give this a shot. Big Daddy thanks a million!!No problem, glad I could help. When I select "server1" is it possible to have a new window pop up and ask me to either "shutdown" "reboot" or "cancel" with the server name in the window? And then do the task I want in the background. I dont really want the c m d . e x e window to pop up. Its not pretty, but I think it will accomplish what you are wanting. expandcollapse popup#include <GUIConstants.au3> ;Script for shutting down specific server Dim $server1 = "Server1";name of server 1 Dim $server2 = "Server2";name of server 2 Dim $server3 = "Server3";name of server 3 Dim $time = "20";seconds to delay shutdown ; GUI $gui1 = GUICreate("Server Shutdown", 200, 100) $s1 = GUICtrlCreateButton($server1, 10, 40) $s2 = GUICtrlCreateButton($server2, 75, 40) $s3 = GUICtrlCreateButton($server3, 140, 40) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $s1 _PopUp($server1) Case $msg = $s2 _PopUp($server2) Case $msg = $s3 _PopUp($server3) EndSelect WEnd Func _PopUp($a_server) GUISetState(@SW_HIDE, $gui1) $gui2 = GUICreate("Server Shutdown", 200, 100, -1, -1, -1, -1, $gui1) $label = GUICtrlCreateLabel("Select command for: " & $a_server, 10, 20) $but1 = GUICtrlCreateButton("Shutdown", 10, 50) $but2 = GUICtrlCreateButton("Restart", 80, 50) $but3 = GUICtrlCreateButton("Cancel", 140, 50) GUISetState(@SW_SHOW, $gui2) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $gui2) ExitLoop Case $msg = $but1 GUISetState(@SW_HIDE, $gui2) Run(@ComSpec & " /c " & "shutdown -s -m \\" & $a_server & " -t " & $time, "", @SW_HIDE);shutdown a pc ExitLoop Case $msg = $but2 GUISetState(@SW_HIDE, $gui2) Run(@ComSpec & " /c " & "shutdown -r -m \\" & $a_server & " -t " & $time, "", @SW_HIDE);restart a pc ExitLoop Case $msg = $but3 GUISetState(@SW_HIDE, $gui2) ExitLoop EndSelect WEnd GUISetState(@SW_SHOW, $gui1) EndFunc ;==>_PopUp Link to comment Share on other sites More sharing options...
XmangiaX Posted February 8, 2006 Author Share Posted February 8, 2006 (edited) Simply put... WOW!!Both of these are awesome! Thank you thank you thank you!!! I need to take it from 3 servers to 25 with Big Daddys idea.... I was running into a small roadblock trying to align my boxes though and it got pretty ugly. I scrapped that piece of code when i shouldve posted it here instead. All i need to learn is how to make more than one row of horizontal buttons and I am golden. Ill probably end up with 3 rows. 5 per row. However, thank you so much for taking the time to help me out. Now I can disect and learn. Thats usually the best way for me. I hope I wasnt to much of a pest. You guys have a good night! Edited February 8, 2006 by XmangiaX Link to comment Share on other sites More sharing options...
skippynz Posted February 8, 2006 Share Posted February 8, 2006 Simply put... WOW!!Both of these are awesome! Thank you thank you thank you!!! I need to take it from 3 servers to 25 with Big Daddys idea.... I was running into a small roadblock trying to align my boxes though and it got pretty ugly. I scrapped that piece of code when i shouldve posted it here instead. All i need to learn is how to make more than one row of horizontal buttins and I am golden. Ill probably end up with 3. 5 per row. However, thank you so much for taking the time to help me out. Now I can disect and learn. Thats usually the best way for me. I hope I wasnt to much of a pest. You guys have a good night!not that my code was tidy - but hey -you get that when you are a novice Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted February 8, 2006 Moderators Share Posted February 8, 2006 All i need to learn is how to make more than one row of horizontal buttons and I am golden. Ill probably end up with 3 rows. 5 per row.You should try either GuiBuilder or Koda which both come with SciTE. They are under the Tools menu. Link to comment Share on other sites More sharing options...
surfer Posted February 8, 2006 Share Posted February 8, 2006 (edited) Hello I need some flexibilityso I wrot that with psshutdown from:http://www.sysinternals.com/Utilities/PsShutdown.htmlyou neet an server.txt file at the same directory with the server names in itexpandcollapse popup#include <file.au3> #include <GuiConstants.au3> #include <Array.au3> ; http://www.sysinternals.com/Utilities/PsShutdown.html Dim $aRecords $file = "server.txt" If Not _FileReadToArray($file ,$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf GuiCreate("Restart the following machines", 210, 460) GUICtrlCreateLabel("Server from the file: "&$file, 10, 10, 180, 95) GUICtrlCreateLabel("________________________________", 10, 25, 180, 95) $counter = 50 $counterOne = 0 $counterOne = $aRecords[0]-1 For $x = 1 to $counterOne ; Dim $Checkbox[$aRecords[0]] ; _arrayAdd( $Checkbox, GuiCtrlCreateCheckbox($aRecords[$x], 25, $counter, 90, 20)) GUICtrlCreateLabel("Server "&$x&": "&$aRecords[$x], 25, $counter, 180, 95) ; $Checkbox= GuiCtrlCreateCheckbox("Server 1", 25, $counter, 90, 20);3 $counter = $counter+20 Next GUICtrlCreateLabel("Server", 10, 170, 80, 95) $server = GUICtrlCreateInput ("", 10, 190, 130, 20) GUICtrlCreateLabel("User", 10, 220, 80, 95) $user = GUICtrlCreateInput ("", 10, 240, 130, 20) GUICtrlCreateLabel("Password", 10, 270, 80, 95) $password = GUICtrlCreateInput ("", 10, 290, 130, 20) $RadioRestart = GuiCtrlCreateRadio("Restart", 10, 330, 90, 20); $RadioShutdown = GuiCtrlCreateRadio("Shutdown", 10, 350, 90, 20); $Button = GuiCtrlCreateButton("OK", 10, 370, 90, 20); GUICtrlSetState(10,$GUI_CHECKED) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button server_1() EndSelect WEnd Func server_1() ; Msgbox(0,'Msg:'&GUICtrlRead($RadioRestart)&" Button:"&$Button & $x, "Restart") ; If GUICtrlRead($Button) = $GUI_CHECKED Then if GUICtrlRead($RadioRestart) = $GUI_CHECKED Then ; restart ; run(psshutdown \\172.22.144.1 -u Administrator -p sdfrtghrtfh -r) Run("cmd.exe") $program = "psshutdown" Send($program&" \\"&GUICtrlRead($server)&" -u "&GUICtrlRead($user)&" -p "&GUICtrlRead($password)&" -r") Send ("{ENTER}") Send ("exit") Send ("{ENTER}") Msgbox(0,'Record:' & $x, "Restart >"&GUICtrlRead($server)) EndIf if GUICtrlRead($RadioShutdown) = $GUI_CHECKED Then ; shutdown Run("cmd.exe") $program = "psshutdown" Send($program&" \\"&GUICtrlRead($server)&" -u "&GUICtrlRead($user)&" -p "&GUICtrlRead($password)) Send ("{ENTER}") Send ("exit") Send ("{ENTER}") Msgbox(0,'Record:' & $x, "Shutdown >"&GUICtrlRead($server)) EndIf ; Else ; EndIf EndFuncI would like to use an combo box or radio buttons: Dim $Checkbox[$aRecords[0]] _arrayAdd( $Checkbox, GuiCtrlCreateCheckbox($aRecords[$x], 25, $counter, 90, 20))if GUICtrlRead($Checkbox[0]) = $GUI_CHECKED ThenMsgbox(0,'Record:' & $Checkbox[0], "Test "& $Checkbox[0])EndIfThis is not recognized from AutoItGUICtrlRead($Checkbox[0])but whyand why is after each line such a letter?But the selection didn't work also the mouse doesn't work only by using TAB.Has somebody an hint? Edited February 8, 2006 by surfer Link to comment Share on other sites More sharing options...
surfer Posted February 10, 2006 Share Posted February 10, 2006 Has somebody an hint? Link to comment Share on other sites More sharing options...
surfer Posted February 10, 2006 Share Posted February 10, 2006 Hello, I've got it: expandcollapse popup#include <file.au3> #include <GuiConstants.au3> #include <Array.au3> ; http://www.sysinternals.com/Utilities/PsShutdown.html Dim $aRecords $file = "server.txt" $server = "XXX" If Not _FileReadToArray($file ,$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf GuiCreate("Server Restart", 210, 400) GUICtrlCreateLabel("Server from the file: "&$file, 10, 10, 180, 95) GUICtrlCreateLabel("________________________________", 10, 25, 180, 95) $counter = 50 $counterOne = 0 $counterOne = $aRecords[0]-1 $listTest = "" $ListServer = GUICtrlCreateList("", 10, 40, 180, 97, -1, $WS_EX_CLIENTEDGE) For $x = 1 to $counterOne $listTest = $listTest&"|"& StringStripCR($aRecords[$x]) GUICtrlSetData(-1, $listTest) $counter = $counter+20 Next GUICtrlCreateLabel("Server", 10, 170, 80, 95) $server = GUICtrlCreateInput ("", 10, 190, 130, 20) GUICtrlCreateLabel("User", 10, 220, 80, 95) $user = GUICtrlCreateInput ("", 10, 240, 130, 20) GUICtrlCreateLabel("Password", 10, 270, 80, 95) $password = GUICtrlCreateInput ("", 10, 290, 130, 20) $RadioRestart = GuiCtrlCreateRadio("Restart", 10, 330, 90, 20); $RadioShutdown = GuiCtrlCreateRadio("Shutdown", 10, 350, 90, 20); $Button = GuiCtrlCreateButton("OK", 10, 370, 90, 20); GUICtrlSetState(10,$GUI_CHECKED) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button server() EndSelect WEnd ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++ Func server() if GUICtrlRead($server) == "" Then $server = $ListServer Endif if GUICtrlRead($server) == 0 Then $server = $ListServer Endif if GUICtrlRead($server) == "Server" Then $server = $ListServer Endif if GUICtrlRead($server) == "0" Then $server = $ListServer Endif if GUICtrlRead($server) == "XXX" Then $server = $ListServer Endif ; Msgbox(4096,'Record:' & GUICtrlRead($ListServer), "Test XXXX>"&GUICtrlRead($ListServer)&" Test2>"&GUICtrlRead($server)) if GUICtrlRead($RadioRestart) = $GUI_CHECKED Then ; restart $message1 = Msgbox(1,'Server Restart:', "Restart >"&GUICtrlRead($server)) if ($message1 == 1) Then Run(@ComSpec & " /c " & "psshutdown \\"&GUICtrlRead($server)&" -u "&GUICtrlRead($user)&" -p "&GUICtrlRead($password)&" -r", "", @SW_HIDE);shutdown a pc Endif EndIf if GUICtrlRead($RadioShutdown) = $GUI_CHECKED Then ; shutdown $message2 = Msgbox(1,'Server Shutdown:', "Shutdown >"&GUICtrlRead($server)) if ($message2 == 1) Then Run(@ComSpec & " /c " & "psshutdown \\"&GUICtrlRead($server)&" -u "&GUICtrlRead($user)&" -p "&GUICtrlRead($password), "", @SW_HIDE);shutdown a pc EndIf EndIf ; Else ; EndIf EndFunc But the mouse doesn't work??? Why ??? Please needd some help !!!!! Thaks a lot surfer 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