Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2005

Tip: Looking for answers? Try searching our database.

how to stop the "password protected" dialog box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy Fish - 21 Jan 2005 11:11 GMT
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
Phil Wilson - 21 Jan 2005 16:00 GMT
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).
Signature

Phil Wilson
[Microsoft MVP-Windows Installer]

> Hi,
>
[quoted text clipped - 28 lines]
>
> Andy
Andy Fish - 21 Jan 2005 16:12 GMT
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 :-(

> 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
[quoted text clipped - 31 lines]
>>
>> Andy
Jonathan West - 21 Jan 2005 16:37 GMT
Hi Andy

Take a look here

Skipping Password-Protected Documents in a Batch Process
http://word.mvps.org/FAQs/MacrosVBA/CheckIfPWProtectB4Open.htm

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

> Hi,
>
[quoted text clipped - 28 lines]
>
> Andy
Andy Fish - 21 Jan 2005 18:01 GMT
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

> Hi Andy
>
[quoted text clipped - 35 lines]
>>
>> Andy
Cindy M  -WordMVP- - 24 Jan 2005 20:35 GMT
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 :-)
Andy Fish - 22 Jan 2005 17:13 GMT
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.

> Hi,
>
[quoted text clipped - 28 lines]
>
> Andy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.