Jump to content

Code using WinActivate/WinExists not working...?


Recommended Posts

I've been trying to determine what is causing my tests to fail, and have run a full battery of slightly different types of tests in using WinActivate and WinExists. All I truly need to know is if the window exists, however - all my tests fail, and therefore the code is not running as expected.

The following snippet are two example tests from my script that contains the slightly different tests. Can someone tell me if I'm using these methods incorrectly?

If 0 == WinExists("[CLASS:ThunderRT5Form;]") Then
    MsgBox(4096, "Shutdown", "LOGIN FOUND! WinExists test number 5.");
Else
    MsgBox(4096, "No Login", "No login found: WinExists test number 5.");
EndIf



If 0 == WinActivate("Please login. The current time is:", "Log In") Then
    MsgBox(4096, "Shutdown", "LOGIN FOUND! WinActivate test number 1.");
Else
    MsgBox(4096, "No Login", "No login found using WinActivate test number 1");
EndIf

I can verify that the window does in fact exist. After the tests go through the "WinExists" methods and start hitting the WinActivate method (and failing), the window becomes active shortly before the MsgBox pops up (and therefore takes control and becomes the active window).

My original code (pretty simple) aims to either forcibly log a person off a machine, or if the application crashed, to restart the machine - if the user's not logged in and the application hasn't crashed (for debugging) I am displaying a message box...but the code's not working due to the WinActivate/WinExists problem:

;force user logoff if logged on
If 1 == WinActivate("Logout - CybraryN(tm)", "Logout") Then
    ControlClick("Logout - CybraryN(tm)", "Logout", "[CLASS:ThunderRT5CommandButton; CLASSNN:ThunderRT5CommandButton2; INSTANCE:2; ID:3; TEXT:Logout;]", "primary");
    WinActivate("CybraryN", "Yes");
    ControlClick("CybraryN", "Yes", "[CLASS:ThunderRT5CommandButton; INSTANCE:2; CLASSNN:ThunderRT5CommandButton2; ID:3; TEXT:Yes;]", "primary");
;force computer restart if logon window is not found
ElseIf 0 == WinExists("Please login. The current time is:") Then
    Shutdown(6);
Else
    MsgBox(4096, "OK", "Nothing to do.");
EndIf

I am running this with the current stable version of AutoIT (v3.2.12.1) on a Windows XP Pro w/SP3 machine, locked down with Microsoft SteadyState. Because of SteadyState, the executable is called remotely using psexec. I am unable to directly run executables on the machines in question, and I am also unable to run the application this is interacting with on any test or development machine to do any debugging while working in the editor.

Can anyone offer any suggestions or tell me what I'm doing wrong?

Edited by BrendonKoz
Link to comment
Share on other sites

Thanks, FireFox, that worked! I feel kind of dumb for not trying that. I was definitely doing something wrong, but from the documentation I thought I was being as explicit as possible:

Return Value

Success: Returns 1 if the window exists.

Failure: Returns 0 otherwise.

Assuming the return value wasn't numerical or boolean, would I have to assign it to a variable in order to test its value, or can I do it all on one line?

Link to comment
Share on other sites

Thanks, FireFox, that worked! I feel kind of dumb for not trying that. I was definitely doing something wrong, but from the documentation I thought I was being as explicit as possible:

Assuming the return value wasn't numerical or boolean, would I have to assign it to a variable in order to test its value, or can I do it all on one line?

Return values is for error or varaibles, here you have if...then so use error code :

If @error then
Msgbox(48,"","Error return value : "&@error)
Else
Msgbox(0,"","No error")
Endif
Link to comment
Share on other sites

  • Developers

Return values is for error or varaibles, here you have if...then so use error code :

If @error then
Msgbox(48,"","Error return value : "&@error)
Else
Msgbox(0,"","No error")
Endif
Huh :) ... what are you saying here ?

@op,

What was the whole code you were using ?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Huh :) ... what are you saying here ?

@op, the issue in your code is the == which doesn;t compare numerically but Alphanumerically.

Jos

@Jos,

I don't know if I'm right but @error return value of error for example 1.

Link to comment
Share on other sites

  • Developers

@Jos,

I don't know if I'm right but @error return value of error for example 1.

The return value is the value returned by the function and has nothing to do with the retuned error code (@error).

example:

$x = WinExist("")

$x is set to 1 when the window exists. @error isn't used by this function so will always be 0.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

The return value is the value returned by the function and has nothing to do with the retuned error code (@error).

example:

$x = WinExist("")

$x is set to 1 when the window exists. @error isn't used by this function so will always be 0.

Jos

Yes,thanks that's why I was thinking :)
Link to comment
Share on other sites

@op,

What was the whole code you were using ?

I was primarily having issues with how to properly use WinExists and WinActivate, so the whole code isn't really necessary to show. The error I was getting is because of how I was comparing the return value in the IF test.

If 1 == WinActivate("Please login.") Then

Although the window itself was activated, the code inside the IF was not executed, it went to the ELSE. (I may have had the wrong return value in the test, however.) Either way, removing the == in the if seems to work.

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