gesher Posted July 15, 2009 Posted July 15, 2009 hello I would like to know is to not allow more than 1 process at a time ? hola quisiera saber como se hace para no permitir mas de 1 proceso a la vez ? This-aplicaion.exe if ProcessExists("This-aplicaion.exe") Then MsgBox(0,"","1") Exit Else MsgBox(0,"","2") EndIf ????
DW1 Posted July 15, 2009 Posted July 15, 2009 Check out "_Singleton()" in the help file. I think it does what you are asking for. AutoIt3 Online Help
gesher Posted July 16, 2009 Author Posted July 16, 2009 thanks expandcollapse popupFunc _Singleton($sOccurenceName, $iFlag = 0) Local Const $ERROR_ALREADY_EXISTS = 183 Local Const $SECURITY_DESCRIPTOR_REVISION = 1 Local $handle, $lastError, $pSecurityAttributes = 0 If BitAND($iFlag, 2) Then Local $structSecurityDescriptor = DllStructCreate("dword[5]") Local $pSecurityDescriptor = DllStructGetPtr($structSecurityDescriptor) Local $aRet = DllCall("advapi32.dll", "int", "InitializeSecurityDescriptor", _ "ptr", $pSecurityDescriptor, "dword", $SECURITY_DESCRIPTOR_REVISION) If Not @error And $aRet[0] Then $aRet = DllCall("advapi32.dll", "int", "SetSecurityDescriptorDacl", _ "ptr", $pSecurityDescriptor, "int", 1, "ptr", 0, "int", 0) If Not @error And $aRet[0] Then Local $structSecurityAttributes = DllStructCreate("dword;ptr;int") DllStructSetData($structSecurityAttributes, 1, DllStructGetSize($structSecurityAttributes)) DllStructSetData($structSecurityAttributes, 2, $pSecurityDescriptor) DllStructSetData($structSecurityAttributes, 3, 0) $pSecurityAttributes = DllStructGetPtr($structSecurityAttributes) EndIf EndIf EndIf $handle = DllCall("kernel32.dll", "int", "CreateMutex", "ptr", $pSecurityAttributes, "long", 1, "str", $sOccurenceName) $lastError = DllCall("kernel32.dll", "int", "GetLastError") If $lastError[0] = $ERROR_ALREADY_EXISTS Then If BitAND($iFlag, 1) Then Return SetError($lastError[0], $lastError[0], 0) Else Exit -1 EndIf EndIf Return $handle[0] EndFunc if _Singleton("test",1) = 0 Then Msgbox(0,"Warning","An occurence of test is already running") Exit EndIf Msgbox(0,"OK","the first occurence of test 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