Archive: How to detect an application is still running


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).


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


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.


Check classname with http://www.catch22.net/software/winspy.asp


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.


Every window has a class, are you using MFC/ATL or something like that or are you calling CreateWindow/DialogBox directly?


I am using quite simpel Visual studio to create a dialog application.


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.


FCT plug-in can solve #32770 problem http://nsis.sourceforge.net/FCT_plug-in