How can you close an application?
There are three general options:
- Kill it outright
- Assuming that it has a main window and that it behaves conventionally, send a
WM_CLOSE
message to that window by P/Invoking SendMessage
- Assuming that it wants to cooperate, use a custom communication channel to tell it to terminate itself
How should you close an application?
Killing a process outright is heavy-handed and should never be attempted unless you know that the process won't be doing anything sensitive when it's terminated. Typically this is used as a last resort.
Telling it to close its main window requires that you first learn what that window's HWND
is somehow; you can do that by walking the list of top-level windows or by having the spawned process somehow communicate it to you. It also assumes that the other process will decide to terminate itself when you ask that its main window be closed (in reality it could decide to do anything, including completely ignore the message). This approach is a reasonable first attempt and it usually works fine with processes which are not under your control -- although you have to find the window yourself.
Using a custom communication channel allows you to completely control what happens and how plus it can be implemented in lots of ways, but it's an approach that involves writing the most code and needs you to have source access to both applications.
Conclusion
It depends. If you are 1000% sure that killing the process won't disrupt anything then that would be a quick and dirty solution; otherwise you need to use one of the two "polite" approaches.
Process
class has anId
you might be able to use it to kill the process.