C# killprocess

Process class has the kill() method to stop a process.

using System.Diagnostics;
Process[] arrp = Process.GetProcesses();
foreach (Process p in arrp)
{
//close the chrome brower
if (p.ProcessName == "chrome") p.kill();
}

Get the process by name and stop it.
using System.Diagnostics;
using System;
try
{
Process p = Process.GetProcessesByName("chrome");
p.kill();
}
catch(Exception ex)
{
System.Console.WriteLine(ex.Message);
}


endmemo.com © 2024  | Terms of Use | Privacy | Home