By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

AutoIt WinClose Function

Use the WinClose function to give programs enough time to close.

Edited: 2015-02-12 19:46

The WinClose function of AutoIt is used to close windows, allowing them enough time to close, and to show potential dialogs, which users may want to respond to.

When WinClose is used on a window, it sends a close message to the window. How the window reacts depends on the program. Some programs might ask the user to save unsaved data for example.

If multiple windows match criteria of the title parameter, the one that was most recently active will be closed.

If you want to forcibly close a window, you can use the WinKill function instead.


TitleThe title of the window.Required
TextThe text of the window to read.Optional

WinClose example

; Attempt to run notepad

; Wait 10 seconds for the window to appear
WinWait("[CLASS:Notepad]", "", 10)

; Wait a couple of seconds before running WinClose

; Now close the window using the saved window handle