Jump to content

WinWaitActive behavior inconsistent on different servers?


Go to solution Solved by ioa747,

Recommended Posts

Hello All,

I'm having trouble with what I assumed would be a very simple portion of a script I'm writing. However, I'm seeing inconsistent results when trying to run it on different Servers. On 3/5 of the Servers, it's working flawlessly, however on 2/5, the application hangs forever. The WinWaitActive doesn't even time-out. The Servers are identical Operating Systems, running the same application. This is the portion of the code I'm having problems with:

; Open CHARON Launcher
    If FileExists("C:\Program Files (x86)\CHARON\Utilities_1.0.12200\Launcher.exe") Then
        Run("C:\Program Files (x86)\CHARON\Utilities_1.0.12200\Launcher.exe")
    Else
        If FileExists("C:\Program Files (x86)\CHARON\Utilities_1.0.14404\x86\Launcher.exe") Then
            Run("C:\Program Files (x86)\CHARON\Utilities_1.0.14404\x86\Launcher.exe")
        Else
            ; Release the mouse back to the user
            _MouseTrap()
            ; Fail Dialog Box
            MsgBox($MB_SYSTEMMODAL, "Warning", "CHARON Launcher Not Found")

            OnExit() ; Exit the Application if the Charon Launcher .exe cannot be found
        EndIf
    EndIf

    ; Wait for the Program Window to become Active
    Local $hWnd = WinWaitActive("CHARON Launcher", 5)
    If Not $hWnd Then
        ; Release the mouse back to the user
        _MouseTrap()
        ; Fail Dialog Box
        MsgBox($MB_SYSTEMMODAL, "Warning", "CHARON Launcher failed to Open")

        OnExit() ; Exit the Application if the Charon Launcher fails to open
    EndIf

This:

WinWaitActive("CHARON Launcher", 5)

is working perfectly on 3 servers, while I'm forced to use:

WinWaitActive("[CLASS:#32770]", "", 5)

in order to make it work on the other 2 servers.

 

To be fair, WinWaitActive("[CLASS:#32770]", "", 5) seems to work on all 5 servers, however I don't like the added ambiguity of relying on any given Windows Diaglog box that happens to pop-up.

 

I've attached a screen capture of the Window Info, side-by-side with the two servers, and highlighted the only minor differences (which I don't think are the cause). I even tried forcing 

Opt("WinTitleMatchMode", 1)

even though it should already be the default, but that had no effect.

 

Any help would be much appreciated.

Thanks!

 

Window Info.png

Link to comment
Share on other sites

Keep in mind that if these are headless servers, you may be running into limitations with Win* actions because the windows don't "really" exist, check out: https://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F

For this use-case locked and headless (as in no remotely connected session with a monitor, or monitor connected to the system) are the same.

Otherwise, there's an issue with your WinWaitActive, where you're using the wrong parameters:

WinWaitActive("CHARON Launcher", 5)

Is wrong, and it should be:

WinWaitActive("CHARON Launcher", "", 5)

Because you're saying that the window must have the "Text" of "5":

WinWaitActive ( "title" [, "text" [, timeout = 0]] )

That's probably why your other WinWaitActive works better, you have the parameters in the correct order there.

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

Thank you very much for the reply mistersquirrle! I read through the headless server FAQ, and I don't believe that's affecting this particular application. I did a test, switching from WinWaitActive, to WinWait, as the FAQ recommends, but that had no effect (I am also running these scripts while the Server is unlocked, viewing through a KVM).

 

Separately from that, your point regarding the WinWaitActive parameter syntax is well taken. I didn't include a bit of my own troubleshooting history in my explanation. I had initially started with:

WinWaitActive("[CLASS:#32770]", "CHARON", 5)

But that didn't work with any of the Servers, and I honestly am still not sure why. This is what led me down the path to WinWaitActive("CHARON Launcher", 5), which I completely agree with you, that isn't correct, and I'm not sure why it even works on 3/5 servers.

 

Is there any reason why WinWaitActive("[CLASS:#32770]", "CHARON", 5) wouldnt work?

 

Link to comment
Share on other sites

Try to activate the window manually and see if WinWaitActive gets triggered.
If yes, don't use WinWaitActivate, instead use WinActivate in combination with WinActive.
Example:

Local $bWndIsActive = False

Do
    WinActivate($hWnd)
    Sleep(1000)
    $bWndIsActive = WinActive($hWnd)
Until ($bWndIsActive)

Of course, you can add something like $iMaxAttempts to quit the loop.

Edited by sylremo
Link to comment
Share on other sites

  • Solution

 

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

;~ WinWaitActive("[TITLE:CHARON; CLASS:#32770]", "", 5)

WinWait("[TITLE:CHARON; CLASS:#32770]", "", 5) ; Better to exempt it from having to be Active

 

Edited by ioa747
corection

I know that I know nothing

Link to comment
Share on other sites

42 minutes ago, ioa747 said:

 

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

;~ WinWaitActive("[TITLE:CHARON; CLASS:#32770]", "", 5)

WinWait("[TITLE:CHARON; CLASS:#32770]", "", 5) ; Better to exempt it from having to be Active

 

 

This is the Solution. I was not understanding how to pass both the TITLE & CLASS parameters together into the WinWait/WinWaitActive functions correctly. Thank you to everyone for your help.

 

Having read back all of the posts. I now realize why the original (bad) code was working on 3/5 of the Servers. As mistersquirrle explained, the Servers that were working just happened to have a configuration file loaded that by coincidence had the "5" character in the filename. Nothing to do with the CHARON Application TITLE (Which is what I was mis-configuring).

Edited by ipc1234
Expanding on the original issue, where the code was working on some Servers, but not all.
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...