@koolzerro This should give you an idea of how to do it passing a message
The other ways would use a similar logic
#include <WinAPI.au3>
Global $gsErr
Global $sBlank = " ";Just to make messagebox wider
HotKeySet("{ESC}", _Exit_Now)
_Main()
;--------------------------------------------------------------------------------------
Func _Create_Message($sMessage)
Local $iMsg = _WinAPI_RegisterWindowMessage($sMessage)
If $iMsg = 0 Then $gsErr &= "IPC Message Creation Failure " & $sMessage & @CRLF
Return $iMsg
EndFunc ;==>_Create_Message
Func _Create_MessageHandler($iMsg, $sFunction)
If $iMsg <> 0 Then
Opt("GUIOnEventMode", 1)
GUICreate(@ScriptName & "_IPC", 0, 0, 0, 0, 0, 0) ; create a top level window
GUIRegisterMsg($iMsg, $sFunction)
EndIf
EndFunc ;==>_Create_MessageHandler
Func _Exit_Now()
OnAutoItExitUnRegister("_Exit_Now")
Exit
EndFunc ;==>_Exit_Now
Func _IsCompiled() ;wakillon
Return @Compiled
EndFunc ;==>_IsCompiled
Func _Main()
If _IsCompiled() Then ;We handle our Single instance here
Local $iActMsg = _Create_Message("@ScriptFullPath" & "_msg")
RunPassThrough($iActMsg)
_Create_MessageHandler($iActMsg, Activated_Ext)
EndIf
OnAutoItExitRegister("_Exit_Now")
While True
Sleep(1000)
WEnd
Exit
EndFunc ;==>_Main
Func Activated_Ext($hWnd, $iMsg, $wParam, $lParam)
;Message Posted from other instances
MsgBox(0, "My Pid = " & @AutoItPID, $sBlank & @CRLF & " Passed From Pid: " & int($lParam) & @CRLF & BinaryToString($wParam))
EndFunc ;==>Activated_Ext
Func RunPassThrough($iActMsg = 0)
Local $sSwitches = $CmdLineRaw
MsgBox(0, "Pass Through " & @AutoItPID, $sBlank & @CRLF & $sSwitches)
RunSingleInstance($iActMsg)
EndFunc ;==>RunPassThrough
Func RunSingleInstance($iActMsg)
Local Const $HWND_BROADCAST = 0xFFFF
If _Singleton_NOCHILD(@ScriptName, 1) = 0 Then
;If $CmdLine[0] > 1 And $CmdLine[1] <> "" Then ;Check Parameters here
_WinAPI_PostMessage($HWND_BROADCAST, $iActMsg, StringToBinary("ASDF"), @AutoItPID) ;passes info back to original instance
;Take Note Of limit of 32 bits for wParam and lParam so 4 8-bit characters if you use text....
;;EndIf
MsgBox(0, @AutoItPID, "Already running : Exiting")
_Exit_Now() ;single instance of script ONLY
EndIf
EndFunc ;==>RunSingleInstance
;;You could just use the singleton function, I removed unneeded functionality from this version
Func _Singleton_NOCHILD($sOccurrenceName, $iFlag = 0) ;Valik
;Without SECURITY_ATTRIBUTES;;;
Local Const $ERROR_ALREADY_EXISTS = 183
Local $aHandle = DllCall("kernel32.dll", "handle", "CreateMutexW", "struct*", 0, "bool", 1, "wstr", $sOccurrenceName)
If @error Then Return SetError(@error, @extended, 0)
Local $aLastError = DllCall("kernel32.dll", "dword", "GetLastError")
If @error Then Return SetError(@error, @extended, 0)
If $aLastError[0] = $ERROR_ALREADY_EXISTS Then
If BitAND($iFlag, 1) Then
DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $aHandle[0])
If @error Then Return SetError(@error, @extended, 0)
Return SetError($aLastError[0], $aLastError[0], 0)
Else
Exit -1
EndIf
EndIf
Return $aHandle[0]
EndFunc ;==>_Singleton_NOCHILD