Tell a running application to close?

Administrator

VB.NET Forum Admin
Joined
Jun 3, 2004
Messages
1,462
Programming Experience
10+
I have an EXE running and then an update comes along. I have an update system, essentially another EXE that drives the MSI updater. During the update process I want to tell the main application to close. I don't want to kill the process, I want to have the application run its close chain such as saving info, etc.

So how can MyApp.EXE that is running receive a message from Update.EXE to close?
 
You have to identify the other app, for example using Process.MainWindowTitle then closing by Process.CloseMainWindow method. It has same effect as user closing the app, but you can see in FormClosing event CloseReason.TaskManagerClosing instead of CloseReason.UserClosing. This is the easiest option and give a clean close, but the app may choose to refuse to close (FormClosing is cancellable). It is also equivalent of using Win32 API call SendMessage to send WM_CLOSE message by the Process.MainWindowHandle. Otherwise you have to implement some IPC functionality in both applications to establish communication and send special messages between them.
 
Back
Top