c#中杀死Excel进程

2025-05-09 19:04:19
推荐回答(2个)
回答1:

#region 杀死进程
private void KillProcess(string processName)
{
//获得进程对象,以用来操作
System.Diagnostics.Process myproc = new System.Diagnostics.Process();
//得到所有打开的进程
try
{
Process[] pros = Process.GetProcesses();
//获得需要杀死的进程名
foreach (Process thisproc in pros)
{
if(thisproc.ProcessName == "EXCEL")
//立即杀死进程
thisproc.Kill();
}
}
catch (Exception Exc)
{
throw new Exception("", Exc);
}
}
#endregion

回答2:

任务管理中不行吗?