Sign in to follow this  
Followers 0
DCSS

WinWait or WinWaitActive

12 posts in this topic

I have a script that works well except for this small inconsistent issue. In this section of the script I wait for an install window to open so I can click on the Install button. Worked fine during testing but when I tried it on two user workstations the script pauses after the install window appears on the screen. If I open the AutoIt icon in the tray (which has a check next to pause), click on exit, click on don't intall in the install window and then rerun my script, it works. I've tried WinWait, WinWaitActive, and even sent an "I", and it does the same thing. Any advise will be much appreciated. :mellow:

;WinWaitActive("Application Install","",5)   Tried this first
        WinWait("Application Install","",5)
    ;   Pauses here during first attempt, works fine during second attempt.
        ControlClick("Application Install","","[NAME:btnInstall; TEXT:&Install; INSTANCE:1]")
    
    ;  This works fine
    WinWait("Invalid","",5)
    sleep(1000)
    if WinExists("Invalid") Then
    ControlClick("Invalid","","[ID:2]")
    sleep(1000)
    Else
        WinWait("WARNING",5)
        sleep(500)
        ControlClick("WARNING","","[ID:2]")
        sleep(1000)
        WinWait("DMV Search Form","",5)
        sleep(500)
        ControlSend("DMV Search Form","","","!e")
        sleep(1000)
    EndIf

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Why do you use 5 seconds as a timeout? Just omit that. Perhaps it takes the installer more than 5 seconds to open after you run your script, and the script already tries to ControlClick something which doesn't exist. Not sure what happens then, but it surely doesn't run ControlClick again.

And btw, as you use ControlSend() commands, you can use WinWait(). It doesn't have to active as you don't use Send() which sends keystrokes to the active window.

~ edit

The timeout should only be used when you are not sure if the specified window will appear. For example, sometimes a program might show a notice you have not installed a certain plugin or whatever. If such a window appears you may want to press 'OK' or something similar, but on other PCs who do have it installed you dont have to do anything. In those situations you might want to use a timeout to give the window an opportunity to show itself.

If the window will always appear, please do not use a timeout as slow computers might take longer to show a specific window. Setting a hard timeout isn't recommended anyway imo, but sometimes your only shot. In your case, you don't need it.

Edited by d4ni

Share this post


Link to post
Share on other sites

I'd suggest using WinWaitActive to make sure that the installation window you want exists, and is currently active so you can interact with it. For good measure, you can put a Sleep for a second or two after WinWaitActive to give the window some extra time to be ready in case it's not immediately ready for input the moment it becomes active.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The window does not have to be active as he uses ControlSend(), not Send(). Try it yourself, you can actually ControlSend() stuff to windows in the background. In my experience, when WinWait passes, you can interact with it in any way you please using ControlSend / ControlClick.

The Sleep() calls you use are not needed either in my experience.

Edited by d4ni

Share this post


Link to post
Share on other sites

Thanx d4ni. I took your suggestion and it did not pause here on my test machines. I am going to try on the user machines and see if it works.

Just curious ... why is there a WinWait and a WinWaitActive? I think I understand what they should do but I don't see a difference. Is one better than the other?

:mellow:

Share this post


Link to post
Share on other sites

Well, WinWaitActive waits until a window exists and is active, whereas WinWait only waits until a window exists :mellow:

Share this post


Link to post
Share on other sites

@d4ni: There are cases where windows don't respond correctly unless they are the active window. I was assuming such a case, just to be sure. There are also cases where a program has not yet finished initializing when its window is already displayed, thus my recommendation for a short delay for safety.

The difference with WinWait and WinWaitActive is just that, the second waits until the window you want is active before proceeding. WinWait is for cases when you want to wait for a window to exist but don't need it to be active before you do stuff. WinWaitActive is for when you need to wait for it to be active.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

In a pretty big script of mine (1000+ lines) I use WinWait 52 unique times, it always works so I don't know about it :mellow: You could be right, but in my experience WinWait is perfectly reliable. Besides, the major thing is I don't want my script to hang when something I do not control suddenly takes focus (= becomes active).

Edited by d4ni

Share this post


Link to post
Share on other sites

Thank you both omikron48 and d4ni. Very good info. I tested the changes on some user machines and no pause, the install script went all the way through with no pause. Now I am going to use the script to deploy software to about 200 workstations.

Thanx again!!! Great software and forum. :mellow:

Share this post


Link to post
Share on other sites

I have one more question. Does using Blockinput() or SplashTextOn affect how WinWait and WinWaitActive work? I added these to my script and it paused waiting for input on the first WinWait.

Thanx in advance for any suggestions.

Share this post


Link to post
Share on other sites

BlockInput shouldn't have an issue since it only deals with user input, not Send or MouseClick. Not sure about SplashTextOn though.

Read in the help file that SplashTextOn creates a window but I can't find a reason for it to meddle with WinWait.

Share this post


Link to post
Share on other sites

Thanx for the prompt reply, I've been playing with this and if I turn off SplashTextOn or resize the Splash window so it does not cover the active window, it seems to work. I haven't found anything in the forums or help that discusses this. Strange!! :mellow:

Thanx again.

Share this post


Link to post
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
Sign in to follow this  
Followers 0