用dsoframer 打开excel 后,关闭dsoframer 怎么删除这个excel进程
不用判断到毫秒,到分钟或者秒级别就行。
/// <summary>
/// 将占用一小时已上的EXCEL进程已经之前打开的EXCEL全部杀掉。
/// 打开EXCEL用时间 分秒毫秒,判断时间来杀EXCEL进程
/// </summary>
public void KillExcelProceed()
{
try
{
PerformanceCounter PC = new PerformanceCounter();//性能计数器
System.Diagnostics.Process[] ExcelProcesses;
ExcelProcesses = System.Diagnostics.Process.GetProcessesByName("EXCEL");
foreach (System.Diagnostics.Process IsProcedding in ExcelProcesses)
{
if (IsProcedding.ProcessName == "EXCEL")
{
PC.InstanceName = IsProcedding.ProcessName;
DateTime start = IsProcedding.StartTime;
TimeSpan ss = DateTime.Now - start;
if ((ss.Hours >= 1 || ss.Minutes > 10) || (startExcelTime.Day == start.Day && startExcelTime.Hour == start.Hour && startExcelTime.Minute == start.Minute && startExcelTime.Second == start.Second && startExcelTime.Millisecond == start.Millisecond))
{
if (!IsProcedding.HasExited)
{
try
{
IsProcedding.Kill();
}
catch (Exception ex)
{
}
}
}
}
}
}
catch (Exception ex)
{
}
}