Jump to content

Take over


Dirk98
 Share

Recommended Posts

Guys, in my script I have a line that waits until a certain browser's window pops up (goes active). Then, when it is active, the code shoots a salvo of different instructions and self-terminates quitely.

But sometimes, in practice, if the ISP line is down the script hangs up because the required window never goes active. Instead I get something like: "Internet Explorer cannot display bla bla bla...".

I nee to add a module, that would wait 90 sec for the required window to go active and if it does not happen, it would take over the control and pass it to the next part that is executed ONLY if/when the main part has failed (not been activated).

Any ideas or your techniques, please?

Many thanks.

Dirk.

Link to comment
Share on other sites

should be easy, lets see some code, and I'll help you.

Thanks, danwilli. Below are principal lines from the script and my notes:

$netname = "LAN connection"
$newIp = "192.168.7.79"
$newSubnet = "255.255.255.0"
$newDG = "192.168.7.1"
$newDNSP = "192.168.9.17"
$newDNSS = "213.251.192.29"
;------------------------------------------------------------------------------------
runwait ('netsh interface ip set address name=' & '"' & $netname & '" static ' & $newIP & ' '& $newSubnet & ' ' & $newDG & ' 1',"",@SW_Hide)
runwait ('netsh interface ip set dns name=' & '"' & $netname & '" static ' & $newDNSP & ' primary',"",@SW_Hide)
runwait ('netsh interface ip add dns name=' & '"' & $netname & '" addr=' & $newDNSS & ' index=2')
ShellExecute ('https://192.168.9.17/login/') 

WinWaitActive ( "Security System Warning" ); <-- If ISP is down this window (uplet) never comes up 

ControlClick ( "Security System Warning", "", 1 )

WinWaitActive ( "Your Start Page - Microsoft Internet Explorer" );<-- If ISP is down then this window doesn't connect
; and instead the script hangs at "Internet Explorer cannot display the webpage"

;---------------------------------------------------------------------------------------------
; here go the lines of my login information if ISP is up
;--------------------------------------------------------------------------------------------


; If ISP is down I want the following module to take over and execute:


$netname = "LAN connection"
$newIp = "192.168.3.39"
$newSubnet = "255.255.255.0"
$newDG = "192.168.3.1"
$newDNSP = "212.188.4.10"
$newDNSS = "195.34.32.116"

runwait ('netsh interface ip set address name=' & '"' & $netname & '" static ' & $newIP & ' '& $newSubnet & ' ' & $newDG & ' 1',"",@SW_Hide)
runwait ('netsh interface ip set dns name=' & '"' & $netname & '" static ' & $newDNSP & ' primary',"",@SW_Hide)
runwait ('netsh interface ip add dns name=' & '"' & $netname & '" addr=' & $newDNSS & ' index=2')
Sleep(1000)
ShellExecute ('http://www.whatismyip.com/')
Sleep(1000)
; script terminates here
Link to comment
Share on other sites

here is a func I wrote up for you, it should be self explanitory... if not, just ask

If TimedWinWait("Untitled - Notepad", 5) Then
    MsgBox(0, "TEST", "win exists")
Else
    MsgBox(0, "TEST", "win does NOT exist")
EndIf



Func TimedWinWait($windowname, $timeout)
    $timer = TimerInit()
    While TimerDiff($timer) < ($timeout * 1000)
        If WinExists($windowname) Then
            Return True
        EndIf
        Sleep(10)
    WEnd
    Return False
EndFunc   ;==>TimedWinWait
Edited by danwilli
Link to comment
Share on other sites

Did that work for you Dirk? or do you need further assistance?

Guys, thank you very much, it's getting too late here to check anything. Danwilli, I'll surely post the result. Thanks again. Looks really good on the first glance.

Dirk.

Edited by Dirk98
Link to comment
Share on other sites

Guys, thank you very much, it's getting too late here to check anything. Danwilli, I'll surely post the result. Thanks again. Looks really good on the first glance.

Dirk.

Danwilli, it works perfect! Nice trigger I've been looking for.

Off to bed and happy. :)

Thanks.

Dirk.

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...