I have the following in a program (written in VB.NET):
Imports Microsoft.Office.Interop.Excel Public Class Form1 Dim eApp As New Excel.Application Dim w As Excel.Workbook w = eApp.Workbooks.Open( 'path.xls', ReadOnly:=True) .. Processing Code .. //Attempts at killing the excel application w.Close() eApp.Workbooks.Close() eApp.Quit() End Class
When I run this a couple of times, I get a bunch of EXCEL.EXE instances in my task manager. How can I kill these processes in code? All of the ones in the code have been tried and did not work.
I had to do this a while back in NET 1.1, so please forgive the rust.
On the eApp, there was a Hwind (a win32 window handle – http://msdn.microsoft.com/en-us/library/bb255823.aspx ) or similar object. I had to use that and a pInvoke (http://www.pinvoke.net/default.aspx/user32.GetWindowThreadProcessId ) to get the process id. With that I was able to do a Process.Kill() on the exe.
There maybe a better way to do it now, but this should work.