Obtain ProcessID for my Excel instance RRS feed

  • Question

  • What forum do I use to resolve the following process ID issue?

    I need to find the process ID for an Excel application object specified by my code.--using Interopt Services. No other Excel processes should be running.

    Following code demonstrates problem.

    DIM aProcess as New Process
    DIM MyExcelProcessID As Integer = -1
    DIM XlsProcesses() as Process = Process.GetProcessesByName("Excel")

    For Each aProcess in XlsProcesses
    DIM xcApp as New Excel.Application
    XlsProcesses = Process.GetProcessesByName("Excel")
    MyExcelProcessID = XlsProcesses(0).ID

    However, if someother program or user opens an Excel process between the process kill loop and the "XlsProcesses = " statement completes then XlsProcesses(0).ID is not guaranteed to be the correct Process ID for xcApp.
    Wednesday, March 10, 2010 1:21 PM