how to stop the "password protected" dialog box

A

Andy Fish

Hi,

I am automating ms word 2003 through .Net office interop, and my app is
running on an unattended server.

If I try to open a password protected document, word pops up a dialog box
asking for the password. Obviously since the machine is unattended, there is
nobody to press cancel, so my process just hangs forever. Infact because
it's running as a service, there's probably not even a dialog box actually
displayed anywhere.

I'm not worried about what happens to that particular document, but I need
to have some way of stopping the calling process hanging. So far my ideas
are (in order of preference):

1. tell word it should never pop-up any dialogs because it's running on a
server

2. find out the process ID of winword.exe when invoking it from COM so I can
kill it from a separate thread (bearing in mind there might be several
winword.exe's running on the same machine)

3. detect up front if the document is password-protected

4. somehow kill the calling thread in .net (thread.abort doesn't work)

can anyone help me accomplish _any_ of these ?

Thanks very much in advance for any hints (other than "don't OLE word from a
server process" - I already know that one)

Andy
 
P

Phil Wilson

Are you sure there isn't an option to open the document specifying the
password? I know MS has been adding those options for automation (it was
added to Access recently).
 
A

Andy Fish

yes, there is a parameter on the Documents.Open() call. Unfortunately my app
won't know the password. If it guesses at a password and that's wrong, the
dialog box pops up so we're back to square 1 again :-(


Phil Wilson said:
Are you sure there isn't an option to open the document specifying the
password? I know MS has been adding those options for automation (it was
added to Access recently).
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Andy Fish said:
Hi,

I am automating ms word 2003 through .Net office interop, and my app is
running on an unattended server.

If I try to open a password protected document, word pops up a dialog box
asking for the password. Obviously since the machine is unattended, there
is nobody to press cancel, so my process just hangs forever. Infact
because it's running as a service, there's probably not even a dialog box
actually displayed anywhere.

I'm not worried about what happens to that particular document, but I
need to have some way of stopping the calling process hanging. So far my
ideas are (in order of preference):

1. tell word it should never pop-up any dialogs because it's running on a
server

2. find out the process ID of winword.exe when invoking it from COM so I
can kill it from a separate thread (bearing in mind there might be
several winword.exe's running on the same machine)

3. detect up front if the document is password-protected

4. somehow kill the calling thread in .net (thread.abort doesn't work)

can anyone help me accomplish _any_ of these ?

Thanks very much in advance for any hints (other than "don't OLE word
from a server process" - I already know that one)

Andy
 
A

Andy Fish

Thanks Jonathan, that certainly helps me with this specific problem.

Unfortunately I guess there are other dialogs that might pop up when opening
a document, so if there is a more general solution I'd be interested to hear
about it.

Andy
 
A

Andy Fish

FWIW here was my solution:

1. find the process ID of the winword.exe you are using. This is not easy
with COM so the only way I could think of is to enumerate all winword.exe
processes just before creating the COM object and then again afterwards.
Compare the two lists and new one is the OOP server you're connected to

2. afer calling thread.abort(), if thread.join() doesn't return in a few
seconds, kill the winword.exe process and call thread.join() again

it's not elegant but it works for me.

in combination with this, I also tried to minimise the dialog boxes word
would pop up by:

1. specifying a dummy password every time I open a document
2. setting DisplayAlerts = none and FeatureInstall = none
3. passing all the parameters to Documents.Open() and Document.Save() so
avoid prompts.
 
C

Cindy M -WordMVP-

Hi Andy,

There's one other, kludgy, possibility that's outlined in a KB article written
for classic VB. Basically, it involves using SendKeys to send an ENTER key if
your application doesn't proceed within a given amount of time. (Similar to the
route you've taken, IOW)

This is one of the main reasons why MS advises to NOT automate Office
applications on a server.
Unfortunately I guess there are other dialogs that might pop up when opening
a document, so if there is a more general solution I'd be interested to hear
about it.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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