如何强制中止某个应用程序的所有进程?

//以中止在Excel进程为例,代码如下:

private void KillExcelProceed()
{
int ProceedingCount = 0;
System.Diagnostics.Process[] ExcelProcesses;
ExcelProcesses = System.Diagnostics.Process.GetProcessesByName("EXCEL");

foreach(System.Diagnostics.Process IsProcedding in ExcelProcesses)
{
if(IsProcedding.ProcessName=="EXCEL")
{
ProceedingCount += 1;
}
}
if(ProceedingCount > 0)
{
DialogResult result;
result=MessageBox.Show("发现系统中有Excel进程,要关闭所有Excel进程吗?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information);

if(result==DialogResult.Yes)
{
foreach(System.Diagnostics.Process myProcess in ExcelProcesses)
{
myProcess.Kill();

}
}
}

}

注意,该段代码将搜索所有的Excel进程并关闭。

Published At
Categories with Web编程
Tagged with
comments powered by Disqus