Preventing interference between multiple Word instances

J

Jason Reichenbach

Controlling Word 2003 from a C#.NET application using the COM interface.

I create a Word object and then perform processing on many files (> 100)
sequentially, with Word invisible. Here is the basic code I use:

Word.ApplicationClass Wrd = new Word.ApplicationClass ();
Word.Document aDoc;

foreach (string curFile in FileCollection) {
aDoc = Wrd.Documents.Open (
// Parameters removed for brevity
);

// Perform document processing on aDoc
aDoc.Close (...);
} // End foreach

Wrd.Quit (...);

This all works fine, Word and the documents stay invisible and all is well.
Unless the user opens another instance of Word while this processing is
underway. Then, the automated instance of Word becomes visible and takes
over, so that the user cannot gain access to the document they wanted to work
on manually (separate from the automated work going on).

Is there any way to avoid this problem? From reading the Word Help, it seems
like maybe the /N startup parameter might work, but I have not found how to
do that using the COM interface to Word.

Specific questions:
1) Is there a way to avoid this interference between Word instances?
2) If 1) is Yes, is the /N parameter the way to do it?
3) If 2) is Yes, how can I duplicate the /N when creating a Word instance
via COM?

Any help will be most appreciated.

Thanks in advance.
 
J

Jezebel

Specific questions:
1) Is there a way to avoid this interference between Word instances?

You can't do it through Word itself. The trick is to stop Windows starting
the new instance in the first place. Locking the keyboard and mouse is
effective.
 
J

Jason Reichenbach

Thanks for the input... Sadly, I don't have the option of locking down the
system. If this can't be done programmitically I'll just have to warn the
users...
 

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