Killing an interop Application process

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.

Answers


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.


loop the below line of code until the result is zero or less

System.Runtime.InteropServices.Marshal.ReleaseComObject(eApp)

or check out this link


Need Your Help

Can JBoss RESTEasy Web Services Use x509 Certificates for Security?

web-services jboss x509certificate resteasy

I am currently in the process of re-writing a legacy asp.net 2.0 web service as a JBoss RESTEasy web service. The asp.net web service uses x509 certificates for security/authentication purposes. ...

Unicode symbols in NSString have wrong dimension

ios objective-c unicode nsstring uialertaction

I'm trying to place two Unicode symbols inside an UIAlectAction. I should have two circles, one empty and the other one filled. My current code is: