Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 Get Process ID (PID) from Word.Application Object

Status
Not open for further replies.

Nsynan

Programmer
Jul 30, 2001
18
US
I am in the stone ages on this project, but is there a way in VB6 to get the Process ID of an instance of Word launched by VB?

For example, somthing like this:
========================================
Dim WordPID as integer
Dim objWD as Word.Application
Set objWD = CreateObject("Word.Application")
WordPID = objWD.???
========================================

The user will have Word already open and the application may have several instances of WinWord.exe open during the application's processing time. I would like to be able to identify which process id to kill if needed in errorhandling.

Thanks
 
Seems to me the simplest way is to set up an array of object pointers. objWD is an example of one. What I don't get from you is whether the application will interact exclusively with Word application instances that it is opened itself or whether it will also need to interact with ones that were opened directly by the user. If the former, all you really have to do is store the object variables in an array. Once you have that, you can do what Hugh suggests.
 
HughLerwill & BobRodes --

As always, thank you guys for helping a poor old broken down; needing to be retired programmer.

Yes BobRodes, the application starts all instances of WinWord.exe to do processing; just the user may have it open as well on their own using it as a reference.

I did think of the array thing, but was just wondering if there was something similar to the PID = shell("winword.exe....) type function, but I guess not with the word object. I couldn't find any such method/property, but never hurts to ask.

But actually the array approach will work fine for me. Sometimes you just need a "nudge" in the right direction.

Thanks again Hugh & Bob,
Nathan
 
You may then want to have a control/getting hold of process id right at the time of its creation. You can use wmi service, win32_precess class, create method. This is the documentation of the create method:
The 4th parameter is an out-param. It gives you the process id. Follow the link back and forth if you are not familiar with the basic of the class, and the documentations are excellent with plenty of illustration examples.
 
There's also all kinds of fun stuff you can do using the API, getting handles to the top level windows (such as Word application instances) and storing them as well. That would be similar to getting the PIDs, but would be fairly complicated. tsuji's method looks to be closest to your original idea, but personally I would prefer to use object pointers anyway, since I could then directly access the Word interface. "myObject(3).Quit" comes to mind as a nice sort of concise bit of code.

I did say an array of object pointers, didn't I? It would be better to use a collection or dictionary object, actually.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top