- Get all processes before the program writes to the excel file.
- Writes to the excel file.
- Get all processes and find new process id. Quit the new process by the process id.
Process[] originalProcesses = Process.GetProcessesByName("Excel");
Application application = new ApplicationClass();
Process[] newProcesses = Process.GetProcessesByName("Excel");
ArrayList list = new ArrayList();
foreach (Process newProcess in newProcesses) {
bool isNew = true;
foreach (Process originalProcess in originalProcesses) {
if (originalProcess.Id == newProcess.Id) {
isNew = false;
break;
}
}
if (isNew) list.Add(newProcess);
}
// Do your stuff
foreach (Process process in list) {
process.Kill();
}
沒有留言:
張貼留言