Jump to content

AutoIT: Forcing a Window to become active


Recommended Posts

Posted

Example:

; Serial Number
$SN_1 = "*****-*****-*****-*****"

Run  ( @ProgramFilesDir & "\Softwin\BitDefender8\bdmcon.exe" )

; Splash Screen
$Title = "BitDefender 8 Professional Plus - Evaluation"
WinWaitActive ( $Title )
ControlClick ( $Title , "" , "Button1" )

; Registration
$Title = "BitDefender 8 Professional Plus - Registration"
WinWaitActive ( $Title )
$SN = StringSplit( $SN_1 , "-" )
ControlSetText ( $Title , "" , "Edit1" , $SN[1] )
ControlSetText ( $Title , "" , "Edit2" , $SN[2] )
ControlSetText ( $Title , "" , "Edit3" , $SN[3] )
ControlSetText ( $Title , "" , "Edit4" , $SN[4] )
ControlClick ( $Title , "" , "Button1" )

; Online #1
$Title = "Online Registration"
WinWaitActive ( $Title )
ControlClick ( $Title , "" , "Button3" )
ControlClick ( $Title , "" , "Button2" )

; Online #2
WinWaitActive ( $Title , "OK" )
ControlClick ( $Title , "OK" , "Button1" )

EXIT

Most of the times, this script works just fine. But sometimes, it gets stuck, mostly on the ; Splash Screen window. Why? Because for some reason it becomes inactive. All it needs is just a click on it, so that it can become active again, and the script continues.

Is there a way, to modify this script, so that if the window becomes inactive, it will force it to become active again, and continue the registration?

Thanks


Posted

I fail to see the reason why you want the windows to be active. The Control*() functions directly operate the controls. You should try to use the text parameters if able to, if needed to prevent a similar window with the same title being recognized incorrectly.

The Splash Screen may not be a problem then, as the script is not concerned if a window is active or not.

Just change all the WinWaitActive() functions to WinWait() functions in your script. Then give it a test. :)

Posted

Try adding this:

If WinExists( $Title ) then ; Check if the window exists

WinActivate( $Title ) ; If so Activate it

EndIf

Posted
I fail to see the reason why you want the windows to be active. The Control*() functions directly operate the controls.

Just to confirm that Control*() functions do not require active windows.

Posted (edited)
Try adding this:

If WinExists( $Title ) then ; Check if the window exists

WinActivate( $Title ) ; If so Activate it

EndIf

i just added it at the top of the file

post-44055-1128503746_thumb.jpg

Edited by Nucleus
Posted (edited)

$Title was not declared before the WinExists function? You must declare or assign a value to a variable before using it, else you will receive the error as you display.

Edit: Allow me to give example.

; Declare a variable
Global $Title

; Assign a variable
$Title = 'Here is a string'

Edited by MHz

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...