- NSIS Discussion
- see if application is running
Archive: see if application is running
MTec007
5th June 2008 11:48 UTC
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:
Wizou
5th June 2008 12:45 UTC
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
MTec007
5th June 2008 13:02 UTC
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?
Wizou
5th June 2008 13:34 UTC
"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
Takhir
5th June 2008 14:56 UTC
http://nsis.sourceforge.net/FCT_plug-in with /WTP option if your plan is to close application.
Wizou
5th June 2008 16:59 UTC
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
MTec007
5th June 2008 21:34 UTC
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?
Red Wine
5th June 2008 22:18 UTC
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
MTec007
6th June 2008 22:59 UTC
i only know that it will begin with "Something.. yeah." all change will be after that.
Afrow UK
7th June 2008 14:24 UTC
In which case you need to use EnumWindows API; or just use FCT plug-in as already mentioned which allows window title part.
Stu
MTec007
8th June 2008 14:10 UTC
how do i use enumwindows?
Animaether
8th June 2008 20:14 UTC
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).
Afrow UK
9th June 2008 13:01 UTC
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
MTec007
9th June 2008 14:26 UTC
Afrow UK: can you give any elaboration? that code is way beyond my comprehension of NSIS' scripting language