How can we get the application window handle or process handle of the excel process which belongs to the excel application instance that we have created? We are using Interop.Excel.dll Version 1.3.0.0. The application class seem to have no HWnd property to call.
Note that it is no solution to simply find all processes with the name excel.exe because we have many excel instances running in parallel and we only want to close a certain instance.
Excel.Application app = new Excel.Application();
// .. do something with excel here
app.Quit();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
// this is in some cases still not enough to get excel killed
uint processID;
GetWindowThreadProcessId((IntPtr)hWnd, out processID); // how to get HWnd from this Excel application?
Process.GetProcessById((int)processID).Kill();