Ok, so what everyone is trying to get at is this.
Applications are not designed to be interfered with by external applications.
This is the application space. Application A should not be able to interfere with the inner workings of Application B without using some sort of public API.
If you really want it to be able to do so, you need to get into the realms of DLL Injection, which is very hacky and not easy to attain.
If you have control over the code of both applications, I would suggest you
- Make the application you wish to shutdown COM visible.
(You should then be able to use script or code to shut it down from an external application)
or
- Open a port on the application you wish to shutdown with a TCPListener class.
Wait for receipt of a shutdown message, then trigger your internal shutdown command. Doing an Application.Quit(); can in effect be the same as a Process.Kill - so if you have some really important business logic that needs to be completed, you would need to wrap the Application.Quit() in your own shutdown logic method.
It would be like this:
App 1 - Starts up
App 1 - Starts the TCPListener on port 12345
App 1 - Starts doing business logic
App 2 - Connects to App1 on port 12345
App 2 - Sends shutdown command
App 1 - Detects the shutdown command and sets an internal variable to say 'No more work should be started
App 1 - Finishes its last work item, then detects that the variable is still set to 'No more work', so it shuts down, having completed its current work item.
This can only be done if you have control over the code of both application or if you are very skilled with DLL Injection and hooking of internal methods.
I've done it in the past where I have injected a dll into a parent application, to create the TCPListener. However, getting it to 'wait' until the current work item is finished, while preventing new items from starting - will be the main complication.