Skip to content
⌘ NSIS Forum Archive

Command or plugin to quit application gracefully?

9 posts

jdt2oo7#

Command or plugin to quit application gracefully?

Hello all,

I've been using the Processes::KillProcess to kill an application before update or before uninstallation, but we are looking for something that give the application time to gracefully shutdown. Any suggestion?

Many thanks!
Animaether#
well, you could send WM_CLOSE to the application:


or you can try the relatively recent nsisDDE plugin:
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
Wizou#
Note: nsisDDE has been around for a long time now (2005) but there was no forum thread for it 😉
Version 1.1 was recently released and supports Unicode.
Animaether#
Originally Posted by Wizou View Post
Note: nsisDDE has been around for a long time now (2005) but there was no forum thread for it 😉
whoops! 🙂
jdt2oo7#
Thanks for your responeses, Animaether and Wizou!

I tried as follow but it doesn't seem to close the program:

nsisDDE::Execute "notepad" "[FileQuit()]"
Pop $0
MessageBox MB_OK "Found $0 responding DDE server(s)"

The message value for $0 is 0.

I also try with nsisDDEW. What I do wrong here?

Thanks!
Animaether#
from the first google hit for 'notepad dde'..
"DDE (Dynamic Data Exchange) is one Microsoft way of communicating between applications that support that (e.g. Word does, but Wordpad/Notepad don't). Messages are strings that express commands"
..it seems notepad doesn't take DDE commands.

So if notepad is your target, WM_CLOSE may be what you're actually looking for. What are you trying to accomplish, exactly?
jdt2oo7#
Thanks Animaether!

I am just trying to quit my application gracefully instead of using Processes::KillProcess to kill my application.

For example, my app is in the process of syncing a file, I would like to quit after the sync process is completed instead of kill the app right away.
Animaether#
Well, you'd have to look up the exact specs of that application's DDE server - if any (e.g. just like notepad, it might not have any) - to use the DDE method.
The alternative is the WM_CLOSE message, which the application should handle gracefully. However, the exact manner in which it handles this is less fine-grained than DDE might allow.

e.g. as per that same article, Microsoft Office Word can be told to close and - if a modified file is open - either save, don't save, or prompt the user.
with WM_CLOSE, it always prompts the user (similar to pressing the X button on the window)
Wizou#
@jdt2oo7 : If you have the source code of your application and it is written in MFC, it is quite easy to add DDE support.