Archive: see if application is running


see if application is running
how do i check to see if my application is running if the title changes? ie it will always start with "Something.. yeah." but after that i dont know what it will be.

!define WNDCLASS "ThunderRT6FormDC"
!define WNDTITLE "Something.. yeah."
FindWindow $0 "${WNDCLASS}" "${WNDTITLE}"
StrCmp $0 0 continueInstall
MessageBox MB_ICONSTOP|MB_OK "The application you are trying to extract is running. Close it and try again."
Abort
continueInstall:


if you're the author of the application, one solution would be to add a DDE server to your application, so you can check if it's running, and even make it close
(just like MS Office apps do to command running instance instead of starting a new one)

see my plugin http://wiz0u.free.fr/prog/nsisDDE/
for how to manipulate DDE commands


I don't really want to go in that direction, adding a DDE server only for the use of the installer? shouldn't there be a better way?


"adding a DDE server" is only a matter of responding to 3 Windows messages, it's not a big overhead, and if you're under MFC it's trivial.

If you can't use FindWindow or you want to give an order to a running instance, DDE is the most adequate solution I've come up with, compared to other forms of inter-process communications.

Other solutions could be to enumerate running processes or to have the running program write its "running state" in the registry but these solutions have flaws (what if the executable has been renamed, or the process was killed, ...)

So the better is to have some cooperation from the running instance, hence the interprocess communication solution


http://nsis.sourceforge.net/FCT_plug-in with /WTP option if your plan is to close application.


note that FCT uses WM_CLOSE
and that WM_CLOSE is not always a correct way to close an application gracefully

see http://blogs.msdn.com/oldnewthing/ar...1/8413175.aspx for more info

"what if the app reacts by minimizing instead, or by displaying a 'save file?' popup.."

(here, FCT kills the process)

but if MTec007 is the author of the app, he should be able to tell if this approach is acceptable


I don't need anything fancy. I don't need to close my application. The user is capable. Does NSIS support some kind of wildcard/regex/anything that I can use to make the code in my original post work?


If you know the possible title changes, this might work:

Function FindWindow

FindWindow $R1 "${WNDCLASS}" "Something.. yeah."
${Unless} $R1 = 0
MessageBox MB_ICONSTOP|MB_OK \
"The application you are trying to extract is running. Close it and try again."
Abort
${EndUnless}
FindWindow $R1 "${WNDCLASS}" "Something different.. yeah."
${Unless} $R1 = 0
MessageBox MB_ICONSTOP|MB_OK \
"The application you are trying to extract is running. Close it and try again."
Abort
${EndUnless}
FindWindow $R1 "${WNDCLASS}" "Something completely different.. yeah."
${Unless} $R1 = 0
MessageBox MB_ICONSTOP|MB_OK \
"The application you are trying to extract is running. Close it and try again."
Abort
${EndUnless}

FunctionEnd

i only know that it will begin with "Something.. yeah." all change will be after that.


In which case you need to use EnumWindows API; or just use FCT plug-in as already mentioned which allows window title part.

Stu


how do i use enumwindows?


or use FindProcDLL; if you can reasonably assume that the process executable name doesn't change; I've had to use this for an application we install for; sometimes its process exists (and DLL files are thusly locked and can't be overwritten) while the Window is not yet in existence or has already closed (but the process not yet exited).


That plug-in does not work on Vista apparently. The System plug-in has an example of using EnumChildWindows which can be modified to use EnumWindows:
http://nsis.sourceforge.net/Docs/Sys....html#callback

Stu


Afrow UK: can you give any elaboration? that code is way beyond my comprehension of NSIS' scripting language