![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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? 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 Specs![]() |
![]() |
| 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 | |||