Talk:CreateMutex plug-in: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
No edit summary |
mNo edit summary |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
Function .onInit | Function .onInit | ||
System::Call 'kernel32::CreateMutexA(i 0, i 0, t " | ; Call the Win32 API to create the mutex. Pass a unique string (ie. product name) | ||
Pop $R0 | System::Call 'kernel32::CreateMutexA(i 0, i 0, t "AnyUniqueText") i .r1 ?e' | ||
Pop $R0 ; Get the mutex handle | |||
; If the create mutex call returns a NULL handle then we can proceed | |||
; otherwise we must bring the already running instance to foreground. | |||
StrCmp $R0 0 noprevinst | StrCmp $R0 0 noprevinst | ||
; Get the window handle from registry | |||
ReadRegStr $R0 HKCU "${PLUGIN_INSTREGKEY}" "WindowHandle" | ReadRegStr $R0 HKCU "${PLUGIN_INSTREGKEY}" "WindowHandle" | ||
System::Call 'user32::SetForegroundWindow(i $R0) i ?e' | System::Call 'user32::SetForegroundWindow(i $R0) i ?e' | ||
Line 20: | Line 24: | ||
FunctionEnd | FunctionEnd | ||
Function . | Function .onGUIInit | ||
; Once the installer GUI is up, store the window handle for use later | |||
WriteRegStr HKCU "${PLUGIN_INSTREGKEY}" "WindowHandle" "$HWNDPARENT" | WriteRegStr HKCU "${PLUGIN_INSTREGKEY}" "WindowHandle" "$HWNDPARENT" | ||
FunctionEnd | FunctionEnd | ||
Function .onGUIEnd | Function .onGUIEnd | ||
; Remove the registry value once installer quits | |||
DeleteRegValue HKCU "${PLUGIN_INSTREGKEY}" "WindowHandle" | DeleteRegValue HKCU "${PLUGIN_INSTREGKEY}" "WindowHandle" | ||
FunctionEnd | FunctionEnd | ||
Line 32: | Line 37: | ||
This code also brings the running instance of the installer to the foreground if starting another instance. | This code also brings the running instance of the installer to the foreground if starting another instance. | ||
:Partly applied as a link to [[Allow_only_one_installer_instance]] page, except the extra code about bringing window to foreground - which is not related to mutexes. -- [[User:Deguix|deguix]] 12:22, 20 January 2006 (PST) |
Latest revision as of 20:24, 20 January 2006
No real need for this plugin as the System.dll plugin alread can do this. Check out this code:
; Just a key to store a window handle in !define PLUGIN_INSTREGKEY "Software\My Company\My Product" Function .onInit ; Call the Win32 API to create the mutex. Pass a unique string (ie. product name) System::Call 'kernel32::CreateMutexA(i 0, i 0, t "AnyUniqueText") i .r1 ?e' Pop $R0 ; Get the mutex handle ; If the create mutex call returns a NULL handle then we can proceed ; otherwise we must bring the already running instance to foreground. StrCmp $R0 0 noprevinst ; Get the window handle from registry ReadRegStr $R0 HKCU "${PLUGIN_INSTREGKEY}" "WindowHandle" System::Call 'user32::SetForegroundWindow(i $R0) i ?e' Abort noprevinst: FunctionEnd Function .onGUIInit ; Once the installer GUI is up, store the window handle for use later WriteRegStr HKCU "${PLUGIN_INSTREGKEY}" "WindowHandle" "$HWNDPARENT" FunctionEnd Function .onGUIEnd ; Remove the registry value once installer quits DeleteRegValue HKCU "${PLUGIN_INSTREGKEY}" "WindowHandle" FunctionEnd
This code also brings the running instance of the installer to the foreground if starting another instance.
- Partly applied as a link to Allow_only_one_installer_instance page, except the extra code about bringing window to foreground - which is not related to mutexes. -- deguix 12:22, 20 January 2006 (PST)