Function Reference


Enforce a design paradigm where only one instance of the script may be running

#include <Misc.au3>
_Singleton ( $sOccurrenceName [, $iFlag = 0] )


$sOccurrenceName String to identify the occurrence of the script. This string may not contain the \ character unless you are placing the object in a namespace (See Remarks).
$iFlag [optional] Behavior options.
0 - Exit the script with the exit code -1 if another instance already exists.
1 - Return from the function without exiting the script.
2 - Allow the object to be accessed by anybody in the system. This is useful if specifying a "Global\" object in a multi-user environment.

Return Value

Success: The handle to the object used for synchronization (a mutex).
Failure: 0


You can place the object in a namespace by prefixing your object name with either "Global\" or "Local\". "Global\" objects combined with the flag 2 are useful in multi-user environments.


#include <Misc.au3>
#include <MsgBoxConstants.au3>

If _Singleton("test", 1) = 0 Then
        MsgBox($MB_SYSTEMMODAL, "Warning", "An occurrence of test is already running")
MsgBox($MB_SYSTEMMODAL, "OK", "the first occurrence of test is running")