首页 > 代码库 > 2012-2-7列举及终止进程
2012-2-7列举及终止进程
System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcessesByName("MSACCESS");
while (ps.Length > 0) { ps[0].Kill();
System.Threading.Thread.Sleep(20);
ps = System.Diagnostics.Process.GetProcessesByName("MSACCESS");
} ///////////// string tempName = "";
int begpos;
int endpos;
foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses()) { tempName = thisProc.ToString();
begpos = tempName.IndexOf("(") + 1;
endpos = tempName.IndexOf(")");
tempName = tempName.Substring(begpos, endpos - begpos);
if (tempName == "MSACCESS")
{
thisProc.Kill();//当发送关闭窗口命令无效时强行结束进程
while (!thisProc.HasExited) System.Threading.Thread.Sleep(10);
System.Threading.Thread.Sleep(100);
}
}
2012-2-7列举及终止进程