_singleton geht nicht unter win 7 64
ich habe folgendes script, was leider nicht das multiple ausführen des scriptes verhindert:
[autoit]
#include <Misc.au3>
Global $ToolTitle = "xyz";
_checkMutex($ToolTitle)
[/autoit][autoit][/autoit][autoit]Func _checkMutex($TileofWin)
if _Singleton($TileofWin,1) = 0 Then
Msgbox(16,"Warning", $TileofWin&" is already running.", 10)
Exit
EndIf
EndFunc
While 1
Sleep(3)
WEnd
hat jemand eine lösung ?
EDIT:
Habe gerade selber eine PID basierende lösung gefunden... wer sie gerne benutzen möchte:
Local $iSingleton = _SingletonPID('myUniqueName', 1)
[/autoit][autoit][/autoit][autoit]If $iSingleton = 0 Then
MsgBox(4096, '', 'This is the first instance of the program running: ' & $iSingleton)
Else
MsgBox(4096, '', 'There is another instance running. This PID is: ' & $iSingleton)
EndIf
; #FUNCTION# ====================================================================================================================
; Name ..........: _SingletonPID
; Description ...: Enforce a design paradigm where only one instance of the script may be running.
; Syntax ........: _SingletonPID($sOccurenceName[, $iFlag = 0])
; Parameters ....: $sOccurenceName - String to identify the occurrence of the script.
; $iFlag - [optional] Optional parameters. Default is 0.
; 0 - Exit the script with the exit code -1 if another instance already exists.
; 1 - Return the PID of the main executable and without exiting the script too.
; Return values .: Success - 0 No other process is running.
; Failure - The PID of the main executable.
; Author ........: guinness with initial ideas by Valik for _Singleton & KaFu for _EnforceSingleInstance.
; Example .......: Yes
; ===============================================================================================================================
Func _SingletonPID($sOccurenceName, $iFlag = 0)
Local $hWnd = WinGetHandle($sOccurenceName)
If @error Then
AutoItWinSetTitle($sOccurenceName)
$hWnd = WinGetHandle($sOccurenceName)
ControlSetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1'), @AutoItPID)
Else
If BitAND($iFlag, 1) Then
Return Number(ControlGetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1')))
Else
Exit -1
EndIf
EndIf
Return 0
EndFunc ;==>_SingletonPID