Robin Vessey
Robin Vessey

Reputation: 4639

How to get instance of an underlying object from System.Diagnostics.Process

Ok what I am trying to achieve is:

Given I have a System.Diagnostics.Process object representing a running application (eg MS Excel) how do I go from having the Process object to holding the active Excel instance?

Ideally it would be something like

Dim lProcess as System.Diagnostics.Process = ProcessOfActiveWindow()
Dim lExcelInstance As Excel.Application

lExcelInsance = DirectCast(lProcess, Excel.Application)

NOTE:

  1. The "DirectCast" is a subsitute for "a miricle occurs here" but hopefully you understand the desired result.
  2. I am not looking for how to get to excel specifically, I'm looking for the "general form" I can apply to any application I happen to know the library definition for.

Upvotes: 0

Views: 135

Answers (1)

John Saunders
John Saunders

Reputation: 161773

There is no "general form". Why should there be. Most applications don't have an API exposing them. There usually is nothing like Excel.Application.

Upvotes: 1

Related Questions