#SingleInstance

Determines whether a script is allowed to run again when it is already running.

#SingleInstance ForceIgnorePromptOff

Parameters

ForceIgnorePromptOff

Type: String

If omitted, it defaults to Force. Otherwise, specify one of the following words:

Force: Skips the dialog box and replaces the old instance automatically, which is similar in effect to the Reload function.

Ignore: Skips the dialog box and leaves the old instance running. In other words, attempts to launch an already-running script are ignored.

Prompt: Displays a dialog box asking whether to keep the old instance or replace it with the new one.

Off: Allows multiple instances of the script to run concurrently.

Remarks

If this directive is unspecified in a script, it will behave as though set to Prompt.

This directive is ignored when any of the following command line switches are used: /force /restart

Like other directives, #SingleInstance cannot be executed conditionally.

By default, the old instance cannot be terminated automatically if it is running at a higher integrity level than the new instance, such as if the old instance was running as admin or with UI access and the new instance is not. [v2.1-alpha.26+]: A WM_CLOSE message is sent to terminate the old instance. To permit all other processes to terminate the script, unblock the WM_CLOSE message as shown below. Previous versions used an undocumented message which should not be unblocked.

DllCall("ChangeWindowMessageFilterEx", "uint", A_ScriptHwnd, "uint", 0x10, "uint", 1, "ptr", 0)

Limitations

Previous instances of the script are identified by searching for a main window with the default title. Therefore, a previous instance may not be found if:

At most one previous instance is detected and sent a message asking it to close. Therefore, the following additional limitations also apply:

If multiple instances of the script are started simultaneously, they may fail to detect each other or may all target the same previous instance. This would result in multiple instances of the script starting.

Reload

Examples

Skips the dialog box and replaces the old instance automatically.

#SingleInstance Force