WinActivate

Activates the specified window.

WinActivate , WinTitle, WinText, ExcludeTitle, ExcludeText

Parameters

WinTitle, WinText, ExcludeTitle, ExcludeText

If each of these is blank or omitted, the Last Found Window will be used. Otherwise, specify for WinTitle a window title or other criteria to identify the target window and/or for WinText a substring from a single text element of the target window (as revealed by the included Window Spy utility).

ExcludeTitle and ExcludeText can be used to exclude one or more windows by their title or text. Their specification is similar to WinTitle and WinText, except that ExcludeTitle does not recognize any criteria other than the window title.

Window titles and text are case-sensitive. By default, hidden windows are not detected and hidden text elements are detected, unless changed with DetectHiddenWindows and DetectHiddenText. By default, a window title must start with the specified WinTitle or ExcludeTitle to be a match, unless changed with SetTitleMatchMode.

Remarks

When an inactive window becomes active, the operating system also makes it foremost (brings it to the top of the stack). This does not occur if the window is already active.

If the window is minimized and inactive, it is automatically restored prior to being activated. [v1.1.20+]: If WinTitle is the letter "A" and the other parameters are omitted, the active window is restored. [v1.1.28.02+]: The window is restored even if it was already active.

Six attempts will be made to activate the target window over the course of 60 ms. If all six attempts fail, WinActivate automatically sends {Alt 2} as a workaround for possible restrictions enforced by the operating system, and then makes a seventh attempt. Thus, it is usually unnecessary to follow WinActivate with WinWaitActive, WinActive() or IfWinNotActive.

In general, if more than one window matches, the topmost matching window (typically the one most recently used) will be activated. If the window is already active, it will be kept active rather than activating any other matching window beneath it. However, if the active window is moved to the bottom of the stack with WinSet Bottom, some other window may be activated even if the active window is a match.

WinActivateBottom activates the bottommost matching window (typically the one least recently used).

GroupActivate activates the next window that matches criteria specified by a window group.

[v1.1.20+]: If the active window is hidden and DetectHiddenWindows is turned off, it is never considered a match. Instead, a visible matching window is activated if one exists.

When a window is activated immediately after the activation of some other window, task bar buttons might start flashing on some systems (depending on OS and settings). To prevent this, use #WinActivateForce.

Known issue: If the script is running on a computer or server being accessed via remote desktop, WinActivate may hang if the remote desktop client is minimized. One workaround is to use commands which don't require window activation, such as ControlSend and ControlClick. Another possible workaround is to apply the following registry setting on the local/client computer:

; Change HKCU to HKLM to affect all users on this system.
RegWrite REG_DWORD, HKCU, Software\Microsoft\Terminal Server Client
    , RemoteDesktop_SuppressWhenMinimized, 2

WinActivateBottom, #WinActivateForce, SetTitleMatchMode, DetectHiddenWindows, Last Found Window, WinExist(), WinActive(), WinWaitActive, WinWait, WinWaitClose, WinClose, GroupActivate, WinSet

Examples

If Notepad does exist, activate it, otherwise activate the calculator.

if WinExist("Untitled - Notepad")
    WinActivate ; Use the window found by WinExist.
else
    WinActivate, Calculator