Jump to content

How would I tell a script to wait for a dialog box, but if it doesn't open within a certain time frame, end the script?


Go to solution Solved by Nine,

Recommended Posts

Basically have an application automation install script for unattended deployment, and sometimes a windows firewall exception dialog pops up, and sometimes it doesn't.

The script currently is set to wait for the two times it pops up, and click ok.

Trouble is, when the boxes never pop up, or only one pops up, the script just sits there forever waiting for the popup, and causes havoc to my process.

I need the script to essentially check for the pop up box for...30 secs? And if it doesn't pop up, end the script.

Is this possible?

 

Thanks guys!

Edited by computerguy4513
Link to comment
Share on other sites

Wouldn't  WinWaitActive do the same, if one set the optional timeout parameter ?

EDIT :

@BigDaddyO was a bit faster :). Yes, WinWait also has an optional timeout parameter.

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

1 hour ago, BigDaddyO said:

if you are using WinWait for the popup, there is a timeout option you can set to 30. 

if WinWait("Firewall", "", 30) = 0 then exit

Just so I understand:

;Windows Security Alert
WinWait('Windows Security Alert')
WinWaitActive('Windows Security Alert')
WinActivate('Windows Security Alert')
;Allow Access(Default)
ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')
;Sleep(5000)
;Windows Security Alert
WinWait('Windows Security Alert')
WinWaitActive('Windows Security Alert')
WinActivate('Windows Security Alert')
;Allow Access(Default)
ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')

In this case, I want the = 0 then exit on the second one to end the script, correct?

Or is the exit portion just for that one line, and I'd want to put that on the end of each?

Link to comment
Share on other sites

Isn't that something like this rather ?

; do something before

CheckSecurityAlert()

; do some other things here

CheckSecurityAlert()

; finalize script after

Func CheckSecurityAlert()
  If WinWait('Windows Security Alert', "", 30) Then
    WinActivate('Windows Security Alert')
    WinWaitActive('Windows Security Alert')
    ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')
  EndIf
EndFunc

 

Link to comment
Share on other sites

25 minutes ago, Nine said:

Isn't that something like this rather ?

; do something before

CheckSecurityAlert()

; do some other things here

CheckSecurityAlert()

; finalize script after

Func CheckSecurityAlert()
  If WinWait('Windows Security Alert', "", 30) Then
    WinActivate('Windows Security Alert')
    WinWaitActive('Windows Security Alert')
    ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')
  EndIf
EndFunc

 

Ahhh I see. So it will check it once, if it's there, it'll close it, then wait again, if it doesn't see one again in 30 secs, it will end the script?

Link to comment
Share on other sites

2 hours ago, Nine said:

Yes I believe this is what it should be, right ?

Maybe this to be safe?

; do something before

CheckSecurityAlert()

; do some other things here

CheckSecurityAlert()

; finalize script after

Func CheckSecurityAlert()
  If WinWait('Windows Security Alert', "", 30) Then
    WinActivate('Windows Security Alert')
    WinWaitActive('Windows Security Alert')
    ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')
  Else
    Exit
  EndIf
EndFunc

Since you may not want to “do some other things here” if you timeout 

Code hard, but don’t hard code...

Link to comment
Share on other sites

Link to comment
Share on other sites

1 hour ago, Nine said:

Really ?  If there is no security alert then exit ?  Really ?

Asking for a friend :)

7 hours ago, computerguy4513 said:

I need the script to essentially check for the pop up box for...30 secs? And if it doesn't pop up, end the script.

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

If WinWait('Windows Security Alert', "", 30) = 0 then exit
    WinActivate('Windows Security Alert')
    WinWaitActive('Windows Security Alert')
    ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')
If WinWait('Windows Security Alert', "", 30) = 0 then exit
    WinActivate('Windows Security Alert')
    WinWaitActive('Windows Security Alert')
    ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')

So it looks like when I run this, the script ends after 30 secs, or if the windows firewall box pops up, and clicks ok. Instead of the "then exit" in the first winwait, is there a bit of code that will tell it to go on if there WAS a popup box within 30 secs which was answered, so it will check for a second before ending?

I'm REAL close, and appreciative of those helping out.

Edited by computerguy4513
Link to comment
Share on other sites

I had some kind of crazy Oracle installer that gave me a random box that would break automation.

I handled it in a different way.  Because I had no idea when it would pop up rather than being in sequence I simply had a AdlibRegister() function checking for that pop up window and if it came up, it would close it.

Worked well for me.

Link to comment
Share on other sites

5 minutes ago, ViciousXUSMC said:

I had some kind of crazy Oracle installer that gave me a random box that would break automation.

I handled it in a different way.  Because I had no idea when it would pop up rather than being in sequence I simply had a AdlibRegister() function checking for that pop up window and if it came up, it would close it.

Worked well for me.

I'll look into it, I'm admittedly not a coder, so I have no idea what that function is, or how to use it properly. 

Link to comment
Share on other sites

;Sleep(5000)
;Windows Security Alert
If WinWait('Windows Security Alert', "", 30) = 1 then
    WinActivate('Windows Security Alert')
    WinWaitActive('Windows Security Alert')
    ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')
Else
If WinWait('Windows Security Alert', "", 30) = 1 then
    WinActivate('Windows Security Alert')
    WinWaitActive('Windows Security Alert')
    ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')
Else
If WinWait('Windows Security Alert', "", 30) = 0 then exit


    EndIf
EndIf

So I REALLY thought this was going to work. However when I ran the install, the script runs, sits in the system tray, and when the Firewall Security box pops up, the script ends, and disappears from the task tray.

I want this script to wait for 30 secs, does the firewall dialog open?

-No? Exit.

-Yes? Click Allow, and wait for another 30 secs to see if the second Firewall dialog opens.

Second dialog opens? 

- No? Exit.

-Yes? Click Allow, then exit script.

 

Like I said, I'm absolutely NOT a programmer by any means, but giving it my best. I feel like the above code SHOULD do that? What am I missing?

Edited by computerguy4513
Link to comment
Share on other sites

WinWait returns 0 OR handle (see help file).  So your 1 is incorrect.

Try this :

;Windows Security Alert (first attempt)
If Not WinWait('Windows Security Alert', "", 30) then Exit
WinActivate('Windows Security Alert')
WinWaitActive('Windows Security Alert')
ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')

;Windows Security Alert (second attempt)
If Not WinWait('Windows Security Alert', "", 30) then Exit
WinActivate('Windows Security Alert')
WinWaitActive('Windows Security Alert')
ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')

Exit

 

Edited by Nine
Link to comment
Share on other sites

17 minutes ago, Nine said:

WinWait returns 0 OR handle (see help file).  So your 1 is incorrect.

Try this :

;Windows Security Alert (first attempt)
If Not WinWait('Windows Security Alert', "", 30) then Exit
WinActivate('Windows Security Alert')
WinWaitActive('Windows Security Alert')
ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')

;Windows Security Alert (second attempt)
If Not WinWait('Windows Security Alert', "", 30) then Exit
WinActivate('Windows Security Alert')
WinWaitActive('Windows Security Alert')
ControlClick('Windows Security Alert','','[CLASS:Button;INSTANCE:6]')

Exit

 

That worked for the first dialog, clicked ok, then the script closed. BUT! That's a step in the right direction! Thank you very much!

I'm learning a lot. I tried putting a "then" statement in the middle, to chain it together...but that didn't work. Maybe a loop of some kind? Which I have no idea how to do. LOL

Link to comment
Share on other sites

  • Solution

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