views:

363

answers:

2

I have a user who has to use Microsoft Word 2007 to create and manipulate word documents in his ASP web application. I'm well aware of the 'Considerations for server-side Automation of Office' KB article and the many third party components available to do this kind of thing, but they've gone a fair bit down this road already.

The problem he's having is that the WINWORD.EXE process never terminates even though he calls Quit on the application object.

For example:

Set objWord = Server.CreateObject("Word.Application")
'' Do work
objWord.Quit
Set objWord = Nothing

As you would expect, his server ends up littered with orphaned WINWORD.EXE processes requiring manual intervention to terminate.

Is there a way to terminate these WINWORD.EXE processes explicitly in the script?

Update:

I've made some progress with this and I think I have a handle on what the problem is. When an Office application runs for the first time under a new Windows account it asks for your name and initials. Now because there is no visible GUI, there is no-one there to push all the right buttons. I've tried starting WINWORD.EXE as the website anonymous account identity using RUNAS, but there's some permission issue that's preventing Word or Office performing some other kind of initial setup routine it wants to do.

+2  A: 

There are two things I can think of:

MyWorkBook.Saved has not been set to true. As a result the Quit call results in WinWord displaying a "Do you wish to save" dialog. On a server. Under a session with no desktop. Needless to say Word never manages to quit as it is waiting for the user.

Your user's script is not always making it to the Quit line. This is a frequent and perhaps biggest reasons against using the Office Automation, as you really need multiple layers of exception handling and finally statements (which isn't VBScript or the ASP classic engines strong point) to ensure that the instance is properly cleaned up.

David
David - thanks for the input. The script as it stands above, where it just instantiates Word.Application and then does Quit, still leaves a process behind. Do I still need to set MyWorkBook.Saved?
Kev
Another thing to try is to ensure the ConnectKind is ckNewInstance, and that AutoQuit is set to True. This would deal with any situation where Word is being left open for reuse. What version of Word is running on the server (I stopped using Automation at Word 2003, never tried it with 2007)
David
It's Word 2007. Which objects are ConnectKind and AutoQuit in?
Kev
David - thanks for time spent on this. Managed to get customer to do the right thing and use a third party component instead.
Kev
A: 

This question is now no longer relevant. Almost all the issues were related to WINWORD.EXE requiring elevated privileges (higher than we allow for web site anonymous user accounts) to be able to perform certain tasks.

Customer has wisely decided to use ASPOSE.Words for .NET which also has a COM callable wrapper so classic ASP code can use it too.

Kev