Start and Kill Processes

The Process component in .NET is a valuable tool for managing applications, providing functionalities for starting, stopping, controlling, and monitoring them. In the context of operating systems, a process refers to a running application, while a thread represents the fundamental unit to which the operating system allocates processor time.

Using the Process component, developers can access a range of capabilities. For example, it allows them to retrieve a list of currently running processes, providing insight into the applications and services that are active on the system. This information can be valuable for monitoring purposes or for performing specific actions based on the processes that are running.

GetProcessesByName

One specific method available within the Process component is GetProcessesByName. By passing a specific process name as an argument to this method, developers can create an array of new Process components associated with all the process resources on the local computer that share the specified name. This facilitates the targeted retrieval of processes with a specific name, enabling developers to perform operations or gather information related to those processes.

Dim _proceses As Process() _proceses = Process.GetProcessesByName("calc")

The above syntax retrieve all the process associated with "calc" application in the _proceses array. System.Diagnostics provides access to local and remote processes and enables you to start and stop local system processes.

The following VB.NET program allows to start multiple calculator applications and later it kill the same instances of all calculator applications.

Full Source VB.NET
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click System.Diagnostics.Process.Start("calc") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim _proceses As Process() _proceses = Process.GetProcessesByName("calc") For Each proces As Process In _proceses proces.Kill() Next End Sub End Class

Conclusion

Using the functionalities provided by the Process component, developers can effectively manage and interact with running applications, gain insights into active processes, and programmatically start new processes. These capabilities empower developers to build robust and dynamic applications that can interact with the operating system and other applications in a controlled and efficient manner.