enaiman Posted May 1, 2007 Posted May 1, 2007 Sorry for opening another topic with this subject - I did a search for "pause" and read alot of previous topics; I guess people get jumpy about this topic ... and they are right because many could be avoided with a minimum research. I'm working on a script which does configuration changes on a big number of network switches (the IP are read from an ini file) The fact is - once I start the process I cannot pause or stop it - it will go on until there is a login error or the end of IP list is reached) Here is the code of the main function expandcollapse popupFunc main_func() Do $current_ip = IniRead($ip_ini, "IP", "ip"&$current_ipno, "") ;read the current IP $tterm_ttl = $current_ip&" - Tera Term VT" ; $delay = Ping($current_ip)+Ping($current_ip)+Ping($current_ip)+Ping($current_ip) $sw_string = "" $begin_time = TimerInit() ;first login - creating the temp admin account $tterm = Run($teraterm&" "&$current_ip&" /L=teraterm.log") Sleep (2000) WinWait($tterm_ttl, "") WinActivate ("Secure Password Changer", "") login("admin", $adminpwd) read_last($tterm_log) If StringInStr ($lastline_content, "*") Then $sw_string = StringMid($lastline_content, 3, 10) Else $sw_string = StringLeft($lastline_content,10 ) EndIf ControlSend($tterm_ttl,"", "","create account admin temp "&$temppwd&@CR) wait_prompt ("#") update_status($sw_string&" Temp admin account created.") ControlSend($tterm_ttl,"", "","logout"&@CR) wait_prompt ("(y/n)") ControlSend($tterm_ttl,"", "","n"&@CR) Do Sleep(200) Until Not WinExists($tterm_ttl, "") ;second login - verifying the temp admin account and changing admin password $tterm = Run($teraterm&" "&$current_ip&" /L=teraterm.log") WinWait($tterm_ttl, "") WinActivate ("Secure Password Changer", "") login("temp", $temppwd) update_status($sw_string&" Temp admin account verified.") ControlSend($tterm_ttl,"", "","configure account admin "&$newadminpwd&@CR) wait_prompt ("#") update_status($sw_string&" Admin password changed.") ControlSend($tterm_ttl,"", "","logout"&@CR) wait_prompt ("(y/n)") ControlSend($tterm_ttl,"", "","n"&@CR) Do Sleep(200) Until Not WinExists($tterm_ttl, "") ;third login - verifying new account password and deleting the temp admin account $tterm = Run($teraterm&" "&$current_ip&" /L=teraterm.log") WinWait($tterm_ttl, "") WinActivate ("Secure Password Changer", "") login("admin", $newadminpwd) update_status($sw_string&" New admin password verified.") ControlSend($tterm_ttl,"", "","delete account temp "&@CR) wait_prompt ("#") update_status($sw_string&" Temp admin account deleted.") ControlSend($tterm_ttl,"", "","logout"&@CR) wait_prompt ("(y/n)") ControlSend($tterm_ttl,"", "","n"&@CR) update_status($sw_string&" Saving configuration.") Do Sleep(200) Until Not WinExists($tterm_ttl, "") GUICtrlSetData ($switches, Int (GUICtrlRead($switches))+1) ;update number of switches processed $current_ipno +=1 ;go to next IP on the list $end_time = TimerDiff($begin_time) ;get the time spent on the switch $time_spent += $end_time ;get the whole time $average_time = $time_spent/Int (GUICtrlRead($switches)) ;get the average $average_time = Round($average_time) ;get rid of decimals time_format() GUICtrlSetData ($avg_time, $swtime) ;display the time If $current_ipno > IniRead($ip_ini, "IP", "ip_count", "") Then ;if the last IP was processed update_status(" ALL passwords changed.") FileClose ($process_log) Return ;get out of this routine EndIf Until $status_flag = 1 Or $temp_flag = 1 EndFunc What could really solve my problem wouldn't be a real "pause" but a way to set $status_flag or $temp_flag to 1 and this will end the main function (after the function is completed) I want to accomplish this by pressing a button. I know it is difficult and I can't imagine a way to do it (I don't wat to use the HotKeySet solution to pause the script). I imagine that OnEventMode is not the easiest way to do this but unfortunately it is to late to do it. Any answer is highly appreciated. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
PsaltyDS Posted May 1, 2007 Posted May 1, 2007 It's not that mysterious. Here is a much shorter script for a demo: expandcollapse popup#include <guiconstants.au3> Opt("GuiOnEventMode", 1) Global $RunFlag = 0, $Cycles = 0 ; Create GUI $hGUI = GUICreate("Pause Demo", 220, 120) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") $Label_1 = GUICtrlCreateLabel("Cycles of main_func() completed: 0", 20, 20, 180, 30, $SS_CENTER) $Button_1 = GUICtrlCreateButton("START", 20, 70, 50, 30) GUICtrlSetOnEvent(-1, "_ButtonHit") $Button_2 = GUICtrlCreateButton("PAUSE", 90, 70, 50, 30) GUICtrlSetOnEvent(-1, "_ButtonHit") $Button_3 = GUICtrlCreateButton("ABORT", 160, 70, 50, 30) GUICtrlSetOnEvent(-1, "_ButtonHit") GUISetState() While 1 If $RunFlag Then main_func() Sleep(100) WEnd Func _ButtonHit() Switch @GUI_CtrlId Case $Button_1 $RunFlag = 1 Case $Button_2 $RunFlag = 0 Case $Button_3 Exit EndSwitch EndFunc Func main_func() GUICtrlSetData($Label_1, "Cycles of main_func() completed: " & $Cycles) $Cycles += 1 Sleep(500) EndFunc ;==>main_func Func _Quit() Exit EndFunc ;==>_Quit Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
enaiman Posted May 1, 2007 Author Posted May 1, 2007 (edited) Great example Thank you I've noticed you used @GUI_CtrlId - is this macro supposed to work on 3.2.2.0 or beta and not on 3.2.1.0? When trying to use it on 3.2.1.0 I get an error "Macro unknown" so I imagine that I should use a newer version ... heh ... here comes another dilemma because of ControlSend which doesn't work properly on 3.2.2.0 and beta . Anyway - You gave me a solution and I am grateful. Thank you again. Edited: Tested it and it works great - I don't get errors about @GUI_CtrlId anymore. You have my eternal gratitude. Edited May 1, 2007 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
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