asp.net 中 如何杀死 服务器上 形成一个 excel.exe的进程

2025-05-09 07:14:07
推荐回答(3个)
回答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);
}
finally
{
GC.Collect();
}
}
#endregion

回答2:

asp.net中杀死服务器上形成的一个excel.exe进程的方法:
1、在 global.asax 中的 Application_OnStart 事件过程中定义计时器,代码如下:
global.asax
<%@ import Namespace="System.Timers" %>

然后简单写一个测试程序来杀掉excel.exe进程:

System.Diagnostics.Process mypro=new Process();
try {
Process[] myProcesses =Process.GetProcessesByName("Excel");
foreach(Process p in myProcesses)
{
if(!p.CloseMainWindow()) {
p.Kill();
}
}
} catch(Exception e2) {
Response.Write( "结束进程失败!原因 "+e2.Message.ToString());
}

回答3:


using System.Diagnostics;
Process[] processes = System.Diagnostics.Process.GetProcessesByName("name");

//自己最好看看通过name得到的是不是你想要杀死的进程
foreach (var item in processes)
{
    item.Kill();
}