Terminate Another Process
Problem
You want to end a process that’s currently running.
Solution
Find the process using Process.GetProcessesByName, and then terminate it using Process.CloseMainWindow or Process.Kill.
Discussion
The Process class provides two methods for ending a process: CloseMainWindow and Kill. CloseMainWindow sends a close message to the main window of an application and is the equivalent of the user closing the window. CloseMainWindow is preferable to Kill because it allows an orderly shutdown. For example, an application such as Microsoft Word will prompt the user to save any open documents. However, CloseMainWindow might not end an application. Most applications will ask for user verification before exiting.
Kill, on the other hand, ...
Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.