thanks
Func _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")