Jump to content

Restart script if winwait doesn't happen


 Share

Recommended Posts

Hi All,

Please excuse my dumbness! I am not a great scripter but have been working on a script for a friend how has had issues with their internet. I have created a script to Ping something like Google if no connection it then runs a script, however, if the issue is with the router rebooting due to a power surge and the page doesn't load, how can I get the script to reboot and start from the beginning?

While 1
$var = Ping("www.google.com")

If not @error Then
MouseMove (0, 728)
MouseClick ("left")
Sleep (500)
MouseClick ("left")
Sleep (1000000)
Else
MouseMove (150, 749)
MouseClick ("left")
Sleep (500)
MouseClick ("left")
run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://192.168.1.1/setup.cgi?next_file=RST_st_poe.htm","")
WinWaitActive("Windows Security")
ControlClick("Windows Security", "", "[CLASS:Edit; INSTANCE:1]")
Send ("{CTRLDOWN}")
Send ("a")
Send ("{CTRLUP}")
Sleep (500)
Send ("****")
Sleep (500)
Send ("{TAB}")
Sleep (500)
Send ("*****")
Sleep (500)
Send ("{ENTER}")
Sleep (5000)
WinWaitActive("NETGEAR Router DGND3700v2 - Windows Internet Explorer")
Send ("{ALTDOWN}")
Sleep (100)
Send ("{SPACE}")
Sleep (100)
Send ("{ALTUP}")
Sleep (500)
Send ("x")
Sleep (3000)
MouseMove (733, 88)
MouseClick ("left")
Sleep (5000)
MouseMove (657, 265)
MouseClick ("left")
Sleep (5000)
ControlClick("Windows Internet Explorer", "", "[CLASS:Button; INSTANCE:1]")
Endif
WEnd

So if the WinWaitActive("Windows Security") isn't found, how can it tell the script to start again?

Please not that the below bit after ELSE is to close all current windows:

MouseMove (150, 749)

MouseClick ("left")

Sleep (500)

MouseClick ("left")

Thanks in advance for any help :)

GSC

Link to comment
Share on other sites

if not WinWaitActive("Windows Security", "", [Timeout]) then ContinueLoop

Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Hi,

Try this :

While 1
    Sleep(10)
    _MyFunc()
WEnd

Func _MyFunc()
    Local Const $iTimeout = 5
    Local $var = Ping("www.google.com")

    If Not @error Then
        MouseMove(0, 728)
        MouseClick("left")
        Sleep(500)
        MouseClick("left")
        Sleep(1000000)
    Else
        MouseMove(150, 749)
        MouseClick("left")
        Sleep(500)
        MouseClick("left")
        Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://192.168.1.1/setup.cgi?next_file=RST_st_poe.htm")
        If WinWaitActive("Windows Security", "", $iTimeout) = 0 Then Return
        ControlClick("Windows Security", "", "[CLASS:Edit; INSTANCE:1]")
        Send("{CTRLDOWN}")
        Send("a")
        Send("{CTRLUP}")
        Sleep(500)
        Send("****")
        Sleep(500)
        Send("{TAB}")
        Sleep(500)
        Send("*****")
        Sleep(500)
        Send("{ENTER}")
        Sleep(5000)
        If WinWaitActive("NETGEAR Router DGND3700v2 - Windows Internet Explorer", "", $iTimeout) = 0 Then Return
        Send("{ALTDOWN}")
        Sleep(100)
        Send("{SPACE}")
        Sleep(100)
        Send("{ALTUP}")
        Sleep(500)
        Send("x")
        Sleep(3000)
        MouseMove(733, 88)
        MouseClick("left")
        Sleep(5000)
        MouseMove(657, 265)
        MouseClick("left")
        Sleep(5000)
        ControlClick("Windows Internet Explorer", "", "[CLASS:Button; INSTANCE:1]")
    EndIf
EndFunc

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

FireFox! you are a genius! thank you so much... I find it all so confusing haha... I have so many scripts that have an issue somewhere or another....

My current issue is that there is other scripts that run but I need something at the beginning of each script that says if the following scripts are working then sleep 10 seconds... any ideas?

GSC

Link to comment
Share on other sites

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Quick note on this... is there a way to make the script keep a log of each time it needs to reconnect the internet? so if it is fine then the mouse clicks something twice, however, if the internet drops it keeps a continuing log of it, and reports even if it timesout and has to start again?

GSC

Link to comment
Share on other sites

My current issue is that there is other scripts that run but I need something at the beginning of each script that says if the following scripts are working then sleep 10 seconds... any ideas?

You can check for function return values/@error macro and if it fails then for example return 0 instead of 1 if it's successful.

While 1
    If _MyFunc() = 0 Then
        Sleep(10000)
    EndIf
    Sleep(10)
WEnd

Func _MyFunc()
    ;do something
    If @error Then Return 0

    Return 1
EndFunc

is there a way to make the script keep a log of each time it needs to reconnect the internet?

Sure, or you go :)

Br, FireFox.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...