[.NET,C#]How to Kill a Windows Process by code

here is a sample code:

using System.Diagnostics;

class FindAndKillProcess {
public bool findAndKillProcess(string pid) {
Process[] processes = Process.GetProcesses();
foreach (Process clsProcess in processes) {
if (clsProcess.Id.ToString().Equals(pid)) {
clsProcess.Kill();
return true;
}
}
return false;
}
}
blog comments powered by Disqus