How to attach to already existing processes?

Juason

Member
Joined
Jul 31, 2006
Messages
8
Programming Experience
Beginner
Howdy,

I am currently using VB.NET and wanting to know how you cycle through and/or attach to already open processes.

For example, I am familiar with open an excel file and manipulating it from within VB. But what if I want to attach to a file the user already has open? How can I do this?

Typically I'd do a

Dim oExcel as Excel.Application
oExcel = CreateObject("Excel.Application") ' Create the Excel Object

and then go about manipulating the object, even going so far as to hide the excel application from the user whilst manipulating it.

But I have been given the challenging of allowing the user to

Dim ps As New ProcessStartInfo
ps.UseShellExecute = True
ps.FileName = MyFile
Process.Start(ps)

To first look at the excel sheet, and then I need to attach to it to read data off of it. I do not want to open the file again as that creates a multitude of problems such as warning me that its already open and read only and all that stuff.

Going further, this knowledge could possibly be useful when attaching to other open applications in the future. I've googled and searched now trying to find some info on how to do this, but nothing has fit the bill. Thank you in advance for any help you can give me with this!
 
Anything of this nature will be purely achievable through what the relevant application makes visible to the system, and wont be generic. For example, a fantastic trick I picked up here from JohnH, when using the dll that is the core of Internet Explorer (shdocvw.dll) there is a static collection of all the open windows which can then be used to get info about them.

If a corollarary is not available for excel, you will have a long and torturous process of decoding windowing messages..

The whole idea of protected memory is that one app cannot simply read and write the memory areas in use by another app..
 
Back
Top