EJUNLIU
21st August 2007 14:26 UTC
How to detect an application is still running
I like to know how to detect if there an application is still running. If yes, the installer can either exit or stop that application.
I saw an example which stops IEFrame.dll and I try to use it to stop my own application. However, it seems not working for my application (a simple executable).
Anders
21st August 2007 14:32 UTC
First you need a way to detect if your application is running, so you normally check for a mutex and/or window class/title, or you can use one of the process enum plugins. If you find a window, you can send it WM_CLOSE/WM_DESTROY or something like that. If your app doesnt have a window you pretty much have to terminate the application with one of the process plugins.
http://nsis.sourceforge.net/Check_wh...uninstallation
http://nsis.sourceforge.net/KillProcDLL_plug-in
http://nsis.sourceforge.net/FindProcDLL_plug-in
EJUNLIU
21st August 2007 14:54 UTC
Thank you!
My code is the almost like:
!define WNDCLASS "WindowClassOfYourApplication"
!define WNDTITLE "WindowTitleOfYourApplication"
Function .onInit
FindWindow $0 "${WNDCLASS}" "${WNDTITLE}"
StrCmp $0 0 continueInstall
MessageBox MB_ICONSTOP|MB_OK "The application is running. Close it and try again."
Abort
continueInstall:
FunctionEnd
However, I have no problem to close something like Notepad.exe. But my own C++ application cannot be even detected (it is visible on Task Manager and it is a simple window application, just a dialog app). Do I miss something? Something like type of application and/or ownership? I thought it is a simple problem but I can't figure out still.
Anders
21st August 2007 15:14 UTC
Check classname with http://www.catch22.net/software/winspy.asp
EJUNLIU
21st August 2007 16:15 UTC
Thanks!
I think the problem is actually related to the class name
in the command:
FindWindow
user_var(hwnd output) windowclass [windowtitle] [windowparent] [childafter]
As my application does not have a proper "windowclass",
so I just use "", and then provide correct "windowtitle", it is working fine. If possible, someone may want to add a note to the help file so it will be easy for other people to use this function in future.
Is anyone can tell me how to assign a windowclass to my application? It seems all my applications created by using Visual Studio 6/NET/2005 do not have any windowclass name.
Anders
21st August 2007 16:45 UTC
Every window has a class, are you using MFC/ATL or something like that or are you calling CreateWindow/DialogBox directly?
EJUNLIU
21st August 2007 17:28 UTC
I am using quite simpel Visual studio to create a dialog application.
EJUNLIU
21st August 2007 18:25 UTC
In fact, I notice that all dialog based applications I created are having the same windowclass as "#32770 (Dialog)". It seems reasonable... but it is hard to know which application is really running. Using windowTitle is a good way if window class cannot help to differentiate 2 applications.
Takhir
21st August 2007 19:34 UTC
FCT plug-in can solve #32770 problem http://nsis.sourceforge.net/FCT_plug-in