Check if a window exists with AutoIt

How to check if a window exists using AutoIt

6165 views

Edited: 2017-07-26 10:41

If you want to check if a given window exists with AutoIt, you will at least need to know the title of the window, alternatively you can also use the window classname.

A single check can be performed using the WinExists function inside an If statement.

If WinExists("[CLASS:Notepad]") Then
    MsgBox(0, "", "Window exists")
EndIf

Waiting for the window to appear

You can also, if needed, use the WinWait function, which allows you to make your script wait for the window to first appear, and create a window handle that you can re-use throughout your script.

$hWnd = WinWait("[CLASS:Notepad]", "", 10)
sleep(10000)
If WinExists($hWnd) Then
  MsgBox(0, "", "Window exists")
ElseIF
  MsgBox(0, "", "Window does not exist")
EndIf

If the window is closed, and a new window opened, the script will show a message that the original window no longer exists.

Tell us what you think:

  1. How to declare and work with variables in AutoIt, as well as some background information.
  2. Everything you need to know about working with minimized windows.
  3. How to set the request headers when performing HTTP requests.
  4. This Tutorial will focus on post requests in AutoIt, using the Winhttprequest.5.1 object.
  5. How to use while, for, and do until loops, and how to loop through arrays and object in AutoIt.

More in: AutoIt Tutorials