Sign in to follow this  
Followers 0
BrendonKoz

Code using WinActivate/WinExists not working...?

9 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Hi,

For not winexists use

If not WinExists("","") then
;something
Endif

And if it exists

If winexists("","") then
;something
EndIf

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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?

Share this post


Link to post
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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

@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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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 :)

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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.

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