Sign in to follow this  
Followers 0

Window Functions with variables

4 posts in this topic

I am trying to control a window using variables to substitute the title and text options. This does not appear to work as the WinWait / WinClose / WinKill may not accept variables. Does anyone have any ideas how to get around this ...


$Window1 = '"Window Title"'

$window2 = '"Window Text"'

WinActivate($Window1, $window2)

WinClose($Window1, $window2)

WinKill($Window1, $window2)

My reason for doing this is to link a default install script to another application script - the default script needs to beable to terminate the application if a winwait timeout occurs. Since the application script could fall over at any stage I need to beable to pipe the failed window to the winclose / winkill function.

Open to ideas

Share this post

Link to post
Share on other sites

how about



Retrieves the internal handle of a window.

WinGetHandle ( "title" [, "text"] )


title The title of the window to read. See Title special definition.

text [optional] The text of the window to read.

Return Value

Success: Returns handle to the window.

Failure: Returns "" (blank string) and sets @error to 1 if no window matches the criteria.


This function is for use with the advanced WinTitleMatchMode options that allow you to use classnames and handles to specify windows rather than "title" and "text".

Once you have obtained the handle you can access the required window even if its title changes.

; Identify the Notepad window that contains the text "this one" and get a handle to it
Run("notepad.exe ")
    Send("this one" & @CRLF)
; Change into the WinTitleMatchMode that supports classnames and handles
AutoItSetOption("WinTitleMatchMode", 4)

; Get the handle of a notepad window that contains "this one"
$handle = WinGetHandle("classname=Notepad", "this one")
If @error Then
    MsgBox(4096, "Error", "Could not find the correct window")
; Send some text directly to this window's edit control
    ControlSend($handle, "", "Edit1", "AbCdE")



Share this post

Link to post
Share on other sites

$AutoItHelp = "AutoIt Help"

WinActivate ($AutoItHelp)

That worked for me.... Maybe it has to do with the number of quotes you used?

Share this post

Link to post
Share on other sites


Reply to Valuater = This looks good however this relies on me picking out the correct window from many open of that given title. - I will keep this as I am sure this will solve another problem - Thanks

Reply to greenmachine = Spot on..... This is exactly what I need - I was nearly there but tried to overcomplicate the variable by defining the quotes(using reverse quotes to wrap it) Tesed on my application and works a treat.... 5 stars to you...

Thanks all for your help and time spent... problem solved.

bourny :lmao:

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