Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - How to GetObject from a process id...?

Reply
 
Old 10-22-2008   #1 (permalink)
chappa-ai


 
 

How to GetObject from a process id...?

VBScript on Windows XP

I don't know if it's possible, but it seems as though it should be. I can
get all the process id's for a given application (for example, multiple Excel
sessions) with...

GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * from Win32_Process
Where Name = 'excel.exe'")

....and then by looping through the collection's ProcessId properties I can
get a unique process id for each running Excel session. But how can I use
that information to get a handle to the application and thus access its
object model?

GetObject(,"Excel.Application") ...will return an (arbitrary?) instance of
the application, but not necessarily the one I'm interested in. By looping
through the process id's I should be able to find the instance which meets a
particular condition and set a handle to it, but I can't find a way to
translate the process id into something compatible with GetObject. Am I
trying to graft wings onto a pig here?

My System SpecsSystem Spec
Old 10-22-2008   #2 (permalink)
mr_unreliable


 
 

Re: How to GetObject from a process id...?

chappa-ai wrote:
Quote:

> GetObject(,"Excel.Application") ...will return an (arbitrary?) instance of
> the application, but not necessarily the one I'm interested in. By looping
> through the process id's I should be able to find the instance which meets a
> particular condition and set a handle to it, but I can't find a way to
> translate the process id into something compatible with GetObject. Am I
> trying to graft wings onto a pig here?
hi chappa-ai,

What you need to do is to read up on the "Running Object Table".
The microsoft office apps (and some others) will place a reference
to themselves in the ROT when they first load. The reference includes
the progid, and a pointer to the IDispatch interface of the app. It is
this IDispatch pointer that is returned when you call "GetObject". The
critical piece of info here is that there is only ONE entry in the ROT
for excel, you will not find an entry for every instance. See here:

http://msdn.microsoft.com/en-us/libr...76(VS.85).aspx

http://support.microsoft.com/kb/238975

In the second (support) page, you will find this:

<quote> NOTE: If there are multiple instances of an automation server
running at the same time, the GetActiveObject() API function returns the
IDispatch pointer to the instance that was first running. </quote>

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Failover Guest Cluster -- 'The process cannot access the file becauseit is being used by another process.' Virtual Server
Process count wrong when only one process matches criteria PowerShell
get-process & stop-process by owner PowerShell
[VBScript](Set objUser = GetObject("WinNT://" & strComputer)) -eq [Powershell]? PowerShell
Bug? Shouldn't Stop-Process automatically match Id if object is a process? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46