antiufo Posted September 3, 2007 Posted September 3, 2007 How can I check if an AutoIt3 script is running using mutex? For example, a script calls _Singleton now I need a script that checks if the first cript is running checking if its mutex exists. How can I do? thanks
martin Posted September 3, 2007 Posted September 3, 2007 How can I check if an AutoIt3 script is running using mutex? For example, a script calls _Singleton now I need a script that checks if the first cript is running checking if its mutex exists. How can I do? thanks The first script runs and calls singleton with the second parameter not set or equal to 0. The first parameter is some string you decide on say $Mstring. The second program calls _Singleton with the same first parameter $Mstring, and the second parameter equal to 1. If the value of @error is 183 after calling _Singleton then the program is already running. Func _Singleton($occurenceName, $flag = 0) Local $ERROR_ALREADY_EXISTS = 183 $occurenceName = StringReplace($occurenceName, "\", ""); to avoid error ; Local $handle = DllCall("kernel32.dll", "int", "CreateSemaphore", "int", 0, "long", 1, "long", 1, "str", $occurenceName) Local $handle = DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $occurenceName) Local $lastError = DllCall("kernel32.dll", "int", "GetLastError") If $lastError[0] = $ERROR_ALREADY_EXISTS Then If $flag = 0 Then Exit -1 Else SetError($lastError[0]);<---flag <>0 so set @error to $ERROR_ALREADY_EXISTS Return 0 EndIf EndIf Return $handle[0] EndFunc ;==>_Singleton Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
antiufo Posted September 4, 2007 Author Posted September 4, 2007 The first script runs and calls singleton with the second parameter not set or equal to 0. The first parameter is some string you decide on say $Mstring.The second program calls _Singleton with the same first parameter $Mstring, and the second parameter equal to 1. If the value of @error is 183 after calling _Singleton then the program is already running.I don't want to create the mutex if the first script is not running. If I call _Singleton in the second script:* If the first script is running I get the right return value (OK)* But if the first script is not running I don't want to create the mutex, I only want to check if the first script is running
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now