Remo1075 Posted May 2, 2009 Posted May 2, 2009 (edited) Hi Guys I have a useable script based on the one below for use on a ticket system that needs updating every 5 minutes. The only problem is, I want it to stop running when it cannot detect the window anymore. Say for instance when the window has been closed manually. Hope you can help Thanks in advance #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.0.0 Author: Script Version: 2.0.0.0 Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- BlockInput(1) ShellExecute(@ProgramFilesDir & "\Internet Explorer\IEXPLORE.EXE", "http://www.yahoo.co.uk") sleep(4000) Send("!d") sleep(1000) send("www.google.co.uk") send("{enter}") BlockInput(0) $i = 0 While $i <= 10 ;refresh 10 times Opt("WinTitleMatchMode", 3) WinActivate("Google - Microsoft Internet Explorer") WinWaitActive("Google - Microsoft Internet Explorer", "", 3) Send("{F5}") ;If WinActive("Google - Microsoft Internet Explorer") = 1 then Send("{F5}") else ;If WinActive("Google - Microsoft Internet Explorer") = 0 then exit I would like to insert something like this, that exits out of the loop if say someone closes the window sleep(5000) ;wait 5 seconds before sending next F5 $i = $i + 1 wend WinClose("Google - Microsoft Internet Explorer") exit Edited May 2, 2009 by Remo1075
John117 Posted May 2, 2009 Posted May 2, 2009 (edited) Remo1075 said: Hi Guys I have a useable script based on the one below for use on a ticket system that needs updating every 5 minutes. The only problem is, I want it to stop running when it cannot detect the window anymore. Say for instance when the window has been closed manually. My suggestion, if you have time is to recode this. It is not that reliable. See the help functions in the help file for IE. You will end up with something like . . . #include <IE.au3.> $oIE = _IECreate(http://www.yahoo.co.uk, 0, 1, 1, 1) $begin = TimerInite() While 1 Sleep(1000) $dif = TimerDiff($begin) If $dif > (5 * 60 * 1000) Then $StillRunning = _IEAction($oIE, "refresh") If $StillRunning <> "1" then Exit $begin = TimerInite() EndIf WEnd Edit: I relly can spell! ;-) Edited May 2, 2009 by John117
Remo1075 Posted May 2, 2009 Author Posted May 2, 2009 Thanks for the quick response, I'll take a look and try figure out what you wrote. It looks a bit complicated for me. Was hoping for a solution with what I had. I know it's not that reliable but at least I understand it. Thanks again. John117 said: My suggestion, if you have time is to recode this. It is not that reliable. See the help functions in the help file for IE. You will end up with something like . . . #include <IE.au3.> $oIE = _IECreate(http://www.yahoo.co.uk, 0, 1, 1, 1) $begin = TimerInite() While 1 Sleep(1000) $dif = TimerDiff($begin) If $dif > (5 * 60 * 1000) Then $StillRunning = _IEAction($oIE, "refresh") If $StillRunning <> "1" then Exit $begin = TimerInite() EndIf WEnd Edit: I relly can spell! ;-)
John117 Posted May 2, 2009 Posted May 2, 2009 (edited) Sorry, what you had was awful! -And far more complicated BTW Break it down. #include <IE.au3.> ;This is just an include . . . "that means its a function a smart member has made for our use!" -they are with the install. $oIE = _IECreate(http://www.yahoo.co.uk, 0, 1, 1, 1) ;-this is a variable ($oIE) -good for recall later, and a function (IECreate) that a member made to open a webpage. $begin = TimerInite() ;This is just a timer. Imagine starting a stop watch here. $begin is the name of the "stop watch" While 1 ;While 1 just keeps on running. Sleep(1000) ;sleep for 1 second. (because you are waiting 5 min, what's a sec or two over 5 min -plus it takes less cpu.) $dif = TimerDiff($begin) ;$Dif is the time since you turned on the stop watch ($begin) If $dif > (5 * 60 * 1000) Then ;If it has been over 5 min (min * Sec * milsec) $StillRunning = _IEAction($oIE, "refresh") ;This is a variable and another function (See smart person ^^^) to preform an IE action "Refresh" -If it works, it returns "1". You can check for "1" by the value of the Variable. You call the $variable anything you want! :-) If $StillRunning <> "1" then Exit ;If the $variable is not "1" -then refresh didn't work! "you can't refresh something that's closed!!! :-) Then Exit! $begin = TimerInite() ; if it didn't exit then it must be open. So lets start the timer again! 5 min here we come! :-) EndIf ;stop $StillRunning test. WEnd ;Start over @ while 1 Edit: Did that help any? -Your post wasn't bad, just more complex, harder to control, and older method. Edit: Try to avoid "Send" when you can. I am guessing it was sending the keystrokes when closed . . . no telling what was recieving them . . . Edited May 2, 2009 by John117
Remo1075 Posted May 2, 2009 Author Posted May 2, 2009 Fantastic, thanks alot Edit: Try to avoid "Send" when you can. I am guessing it was sending the keystrokes when closed . . . no telling what was recieving them . . . you're right other webpages were getting refreshed if the target page closed John117 said: Sorry, what you had was awful! -And far more complicated BTW Break it down. #include <IE.au3.> ;This is just an include . . . "that means its a function a smart member has made for our use!" -they are with the install. $oIE = _IECreate(http://www.yahoo.co.uk, 0, 1, 1, 1) ;-this is a variable ($oIE) -good for recall later, and a function (IECreate) that a member made to open a webpage. $begin = TimerInite() ;This is just a timer. Imagine starting a stop watch here. $begin is the name of the "stop watch" While 1 ;While 1 just keeps on running. Sleep(1000) ;sleep for 1 second. (because you are waiting 5 min, what's a sec or two over 5 min -plus it takes less cpu.) $dif = TimerDiff($begin) ;$Dif is the time since you turned on the stop watch ($begin) If $dif > (5 * 60 * 1000) Then ;If it has been over 5 min (min * Sec * milsec) $StillRunning = _IEAction($oIE, "refresh") ;This is a variable and another function (See smart person ^^^) to preform an IE action "Refresh" -If it works, it returns "1". You can check for "1" by the value of the Variable. You call the $variable anything you want! :-) If $StillRunning <> "1" then Exit ;If the $variable is not "1" -then refresh didn't work! "you can't refresh something that's closed!!! :-) Then Exit! $begin = TimerInite() ; if it didn't exit then it must be open. So lets start the timer again! 5 min here we come! :-) EndIf ;stop $StillRunning test. WEnd ;Start over @ while 1 Edit: Did that help any? -Your post wasn't bad, just more complex, harder to control, and older method. Edit: Try to avoid "Send" when you can. I am guessing it was sending the keystrokes when closed . . . no telling what was recieving them . . .
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