。net定时关闭excel进程
public void Application_Start()
{
// 在应用程序启动时运行的代码
System.Timers.Timer timer = new System.Timers.Timer(1000);
timer.AutoReset = true;
timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(killAllProcess);
}
public void killAllProcess(object sender, EventArgs e)
{
System.Diagnostics.Process[] myPs;
myPs = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process p in myPs)
{
if (p.Id != 0)
{
try
{
if (p.Modules != null)
if (p.Modules.Count > 0)
{
System.Diagnostics.ProcessModule pm = p.Modules[0];
if (pm.ModuleName.ToUpper().Contains("EXCEL"))
p.Kill();
}
}
catch
{
}
finally
{
}
}
}
}