Start and Kill Processes in C#

A system process is uniquely identified on the system by its process identifier. Using the Process component, you can obtain a list of the processes that are running, or you can start a new process in the system. The System.Diagnostics namespace provides classes that allow you to interact with system processes, event logs, and performance counters.

Process[] _proceses = null; _proceses = Process.GetProcessesByName("calc");

Process.GetProcessesByName("calc") - Creates an array of new Process components and associates them with all the process resources on the local computer that share the specified process name. The following C# program allows to start multiple calculator applications and later it kill the same instances of all calculator applications.

Full Source C#
using System; using System.Windows.Forms; using System.Diagnostics; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("calc"); } private void button2_Click(object sender, EventArgs e) { Process[] _proceses = null; _proceses = Process.GetProcessesByName("calc"); foreach (Process proces in _proceses) { proces.Kill(); } } } }