C#中强制关闭某个进程
/// <summary>
/// 关闭进程
/// </summary>
/// <param name="processName">进程名</param>
private void KillProcess(string processName)
{
Process[] myproc = Process.GetProcesses();
foreach (Process item in myproc)
{
if (item.ProcessName == processName)
{
item.Kill();
}
}
}
//强制关闭最近打开的某个进程
private void KillRecentProcess(string processName)
{
System.Diagnostics.Process[] Proc = System.Diagnostics.Process.GetProcessesByName(processName);
System.DateTime startTime = new DateTime();
int m, killId = 0;
for (m = 0; m < Proc.Length; m++)
{
if (startTime < Proc[m].StartTime)
{
startTime = Proc[m].StartTime;
killId = m;
}
}
if (Proc[killId].HasExited == false)
{
Proc[killId].Kill();
}
}