Hello all,
Im looking to find out if its possible to return a handle to the process ID (NOT process name) of a spawned instance of winword.exe
the code here (excuse it being in VB, i knocked together a very quick test):
[code]
strPrintFile = "C:\Documents and Settings\billsmith\My Documents\test\Test.doc"
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
WordApp = CreateObject("Word.Application")
WordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
WordDoc = WordApp.Documents.Open(FileName:=strPrintFile, ConfirmConversions:=
False, ReadOnly:=True)
WordDoc.Activate()
WordDoc.PrintOut(
False) ' Without background printing
WordDoc.Close(
False)
WordApp.Quit(
False)
WordDoc =
Nothing
WordApp =
Nothing
[/code]
Works fine so long as there is no issue with the word document. My application (will) runs unattended, as a windows service. If for instance, the file i was playing with was password protected, the program would sit there forever, untill restarted, expecting someone to handle the password prompt (thats suppressed anyway due to running as a service).
In the past ive written a program to kill by name any long running unresponsive code. However, this was always done by process name, not id. It just so happens we have several services running at a time in this manner (preforming different word functions). Its not feasible for me to kill off all running winword.exe processes since that raises exceptions for other programs, which may have been running fine.
What i need is some way of being able to identify that a particular instance of winword.exe was created from a particular program.
Is there a way to do this? for instance a is there a function to use, or even a property exposed from word.application/document that returns a process handle? Something outside the object model to do this?
I am aware what im doing isnt strictly supported by microsoft due to the whole office automation/unattended applications thing. But surely others have had similar issues...
Many Thanks,
Andrew