I have an object of Excel, sheet.Excel.Application eApp
.
How do I get the process ID of this Excel application and how do I kill that process?
I have an object of Excel, sheet.Excel.Application eApp
.
How do I get the process ID of this Excel application and how do I kill that process?
In addition to the normal Quit
method of the ApplicationClass
class, you can try the below, though it is subject to some, but not all, of the pitfalls mentioned in the link @Mark Pim suggested.
System.Diagnostics.Process[] myProcesses;
// Returns array containing all instances of Excel.
myProcesses = System.Diagnostics.Process.GetProcessesByName("Excel");
foreach (System.Diagnostics.Process myProcess in myProcesses)
{
if (myProcess.MainWindowTitle == Globals.ThisWorkbook.Application.Caption)
{
myProcess.Kill();
}
}