Waits until no matching windows can be found.

WinWaitClose WinTitle, WinText, Timeout, ExcludeTitle, ExcludeText



Type: String, Integer or Object

A window title or other criteria identifying the target window. See WinTitle.


Type: String

If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON.


Type: Integer or Float

How many seconds to wait before timing out and returning 0. Leave blank to allow the function to wait indefinitely.


Type: String

Windows whose titles include this value will not be considered.


Type: String

Windows whose text include this value will not be considered.

Return Value

Type: Integer (boolean)

This function returns 0 (false) if the function timed out or 1 (true) otherwise.


Whenever no matching windows exist, the function will not wait for Timeout to expire. Instead, it will immediately return 1 and the script will continue executing. Conversely, the function may continue waiting even after a matching window is closed, until no more matching windows can be found.

Since "A" matches whichever window is active at any given moment, WinWaitClose "A" typically waits indefinitely. To instead wait for the current active window to close, specify its title or unique ID as in the following example:

WinWaitClose WinExist("A")

WinWaitClose updates the Last Found Window whenever it finds a matching window. One use for this is to identify or operate on the window after the function times out. For example:

Gui("", "Test window " Random()).Show("w300 h50")  ; Show a test window.
if !WinWaitClose("Test",, 5)  ; Wait 5 seconds for someone to close it.
    MsgBox "Window not yet closed: " WinGetTitle()
    WinClose  ; Close the window found by WinWaitClose.

While the function is in a waiting state, new threads can be launched via hotkey, custom menu item, or timer.

If another thread changes the contents of any variable(s) that were used for this function's parameters, the function will not see the change -- it will continue to use the title and text that were originally present in the variables when the function first started waiting.

Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on, even if WinTitle is a HWND or object.

WinClose, WinWait, WinWaitActive, WinExist, WinActive, ProcessWaitClose, SetTitleMatchMode, DetectHiddenWindows


Opens Notepad, waits until it exists and then waits until it is closed.

Run "notepad.exe"
WinWait "Untitled - Notepad"
WinWaitClose ; Use the window found by WinWait.
MsgBox "Notepad is now closed."