Kill Word Process Programmatically

S

Stephen Barrett

Hi all,

I am currently using VB to interface to WORD through COM. Basically, I am
creating a txt based mailmerge file, opening a specific mailmerge document,
merging it with created file, and printing it to a pseudo printer that
converts the document to a PDF file.

I have no control over the authoring of the mail merge document. This
process runs on a server non-interactively. I FULLY understand that Word is
not meant to run as a service process due to all the documented reasons and
MGMT understands it as well. However, we are where we are.

There are certain things that users can do that causes Word to absolutely go
crazy and end up eating tons of CPU. In fact, one user managed to created a
document that had very complicated table nesting within IFF conditions that
actually inadvertently generated unlimited number of print pages. They
kicked this off numerous times and brought the server to its knees.

I would like to be able to kill the Word process directly after a set time
to help protect the server. I can't do this through COM because it is
basically waiting on the merge/print to finish that is causing the problem.
I was hoping that there is a way for me to determine the windows process id
or something else when I activate word and open the document. We are using
Word 2003 so it creates a separate process for each activation and open.
This is multiuser so I can't simply query the processes from Windows looking
for winword.exe. I most likely will get multiple processes for it. I need
a way to know which one is for the rogue process I want to kill.

Any help would be GREATLY appreciated.

TIA
Stephen
 
J

Jan Kucera

Hi Stephen,
which OS and language are you using?

I have two stupid ideas. First, enumerate running processes just before and
after starting the Word. The new one will be the one you might be looking
for. However, this will fail when they are lot of users opening the Word the
same time.

Second is, as Windows does, you can detect whether the Word application is
unresponsive and if it is, kill it no matter who it belongs to.

If your application runs impersonated you could also ask for the process
owner.

Thats all for now I have...
Jan.
 
J

Jan Kucera

Oh VB, I see. Classic VB?
Or you can also monitor the process CPU usage.

Doing that by external application would be safer, since debugging
multithreaded VB is REALLY tricky! ;-)

Jan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top