How to get the process identifier from a running object?
Dim xlApp As Object = CreateObject("Excel.Application")
I need to use the latest binding because I cannot guarantee which version I will get, so using Microsoft.Office.Interop.Excel will not work.
'do some work with xlApp xlApp.Quit System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) xlApp = nothing
At this point, Excel is still running in the background. I got acquainted with all the recommendations for using variables and their release, and then use: System.Runtime.InteropServices.Marshal.ReleaseComObject(o) . This does not work reliably. The work that I do is very difficult. I use for each cycle, etc., using multiple files. Unable to release all resources in Excel. I need a better option.
I would like to use Process.Kill in Excel, but I don't know how to get this process from an xlApp object. I do not want to kill all Excel processes, because the user may have a workbook open.
I tried using Dim xProc As Process = Process.Start(ExcelPath) and then using xProc.Kill() This works sometimes, except it is a little difficult to get the correct Excel object using XLApp = GetObject("Book1").Application or XLApp = GetObject("", "Excel.Application") if the user already has Excel windows. I need a better option.
I cannot use GetActiveObject or BindToMoniker to get an Excel object, because they only work with work when using early binding. For example. Microsoft.Office.Interop.Excel
How to get the process ID from a running object?
Edit: Actually, I am not interested in rethinking how to get Excel to exit well. This was discussed by many other questions. here and here I just want to kill him; clean, accurate and direct. I want to kill the exact process that I started, and no one else.
D_Bester Jul 20 '13 at 5:42 on 2013-07-20 05:42
source share