Killing Processes from a Visual Basic Application

This article provides a simple example of how to use the System.Diagnostics.Process library to display a list of running processes, and to select and kill processes by their process name and ID. It would not be a major trick to display additional information about the process using the same library or to kill processes by their ID or name alone rather than their name and ID but in this example, process names and IDs are used for display purposes and the purpose of killing a running process.


Figure 1: Listing and Killing Processes by Process Name and ID

Getting Started

There is a single solution included with this download, the solution contains a Win Forms project called “ProcessKillerVB”; this project contains one form (Form1.vb) and all of the code required to display and kill processes is contained within that single form class. If you open the attached project into Visual Studio 2008; you should see the following in the solution explorer:


Figure 2: Solution Explorer

Code: The Main Form

The main form contains all of the user interface elements necessary to display and update the list of currently running processes found on the user’s machine. It also contains a button handler which will kill a process by the process name. You can also kill a process by its ID but in terms of readability, if the user is selecting the process, the process name is going to make a lot more sense to them than will the process ID.

Read more of this post