Search code examples
executableautoit

How do I check if AutoIt3 executable is already running?


After compiling my AutoIt v3 script into an EXE executable, I want to ensure that only one instance can be run at a time. What's the best way to achieve this?


Solution

  • What you need is a _Singleton

    #include <Misc.au3>
    #include <MsgBoxConstants.au3>
    
    If _Singleton("test", 1) = 0 Then
        MsgBox($MB_SYSTEMMODAL, "Warning", "An occurrence of test is already running")
        Exit
    EndIf
    MsgBox($MB_SYSTEMMODAL, "OK", "the first occurrence of test is running")