| 1 | #cs ---------------------------------------------------------------------------- |
|---|
| 2 | Script Function: |
|---|
| 3 | Include this at the beginning to make sure only one instance runs |
|---|
| 4 | #ce ---------------------------------------------------------------------------- |
|---|
| 5 | #include-once |
|---|
| 6 | |
|---|
| 7 | If _MutexExists(@ScriptName) Then |
|---|
| 8 | Exit |
|---|
| 9 | EndIf |
|---|
| 10 | |
|---|
| 11 | Func _MutexExists($sOccurenceName) |
|---|
| 12 | Local $ERROR_ALREADY_EXISTS = 183, $handle, $lastError |
|---|
| 13 | |
|---|
| 14 | $sOccurenceName = StringReplace($sOccurenceName, "\", ""); to avoid error |
|---|
| 15 | $handle = DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $sOccurenceName) |
|---|
| 16 | |
|---|
| 17 | $lastError = DllCall("kernel32.dll", "int", "GetLastError") |
|---|
| 18 | Return $lastError[0] = $ERROR_ALREADY_EXISTS |
|---|
| 19 | |
|---|
| 20 | EndFunc ;==>_MutexExists |
|---|
| 21 | |
|---|