lopardo2003
16th October 2004 22:46 UTC
detecting and closing previous instances
Hi. I've searched about this in many places but couldn't find anything useful. So, how can I detect and close previous instances of my application from the NSIS installer, just like the Winamp installer does?
Thanks a lot.
Joel
17th October 2004 19:16 UTC
Did you try it with FindWindowEx API?
There you can use your CLASS to dectect your Application?
Winamp uses FindWindow API with the parameter "Winamp v1.0" as the window title.
Maybe you should do that, too.
:)
deguix
17th October 2004 19:25 UTC
FindWindow syntax:
FindWindow user_var(hwnd output) windowclass [windowtitle] [windowparent] [childafter]
Example:
FindWindow $0 "#32770" "" $HWNDPARENT
Afrow UK
17th October 2004 20:45 UTC
This works nicely:
!define Title "MapUpdater"
!define Version "v0.2b"
Function .onInit
## Check MapUpdater is not already running
Push $R0
FindWindow $R0 "" "${Title} ${Version}" $HWNDPARENT
StrCmp $R0 0 +3
MessageBox MB_OK|MB_ICONSTOP "${Title} is already running!"
Quit
Pop $R0
FunctionEnd
-Stu
iceman_k
20th October 2004 19:26 UTC
If your application is a non-windowed application, use a combo of FindProc and KillProc.
FindProc will tell you if the application is running.
You can then inform the user and use KillProc to kill the process if necessary.
YooperNC
25th January 2005 16:52 UTC
I read the warning in the KillProc description, and now I have a question: Why use TerminateProcess when ExitProcess sounds like it would be the prefered method?
Thanks.
Dave
iceman_k
25th January 2005 17:21 UTC
Because it is guaranteed to kill the process.
ExitProcess may result in a deadlock.
See ExitProcess.