How can I start a "private" version of Word?

A

Alex

Hello,

We have a program that uses Word automation to perform some operations on a set of documents.

However, we have a problem:

The processing can be quite lengthy and if during that time the user tries to do some other work in Word, they will interfere with the process.

What we would like to do:

1) Launch a new instance of msword.exe from our program and automate it, so that existing instance(s) will not be affected.

2) The launched instance should be hidden from the user. No UI, an no way the user can manually interfere with the operation.

3) If the user tries to open a new Word document, this msword.exe instance will *not* be used for it. The document will open in either a previously running instance or a new one will be launched to handle it.

How can I achieve this goal?

Thank you!


Best wishes,
Alex.
 
J

Jonathan West

Hi Alex,

Use CreateObject to start a new instance of Word.Application.
Set the Visible property of that instance to False

Beware, there are gotchas involved in using an invisible instance of Word.
Take a look at this article

How to speed up Word Automation by hiding the application
http://www.word.mvps.org/FAQs/InterDev/MakeAppInvisible.htm

You will need to be very thorough about your testing.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org




Hello,

We have a program that uses Word automation to perform some operations on a
set of documents.

However, we have a problem:

The processing can be quite lengthy and if during that time the user tries
to do some other work in Word, they will interfere with the process.

What we would like to do:

1) Launch a new instance of msword.exe from our program and automate it, so
that existing instance(s) will not be affected.

2) The launched instance should be hidden from the user. No UI, an no way
the user can manually interfere with the operation.

3) If the user tries to open a new Word document, this msword.exe instance
will *not* be used for it. The document will open in either a previously
running instance or a new one will be launched to handle it.

How can I achieve this goal?

Thank you!


Best wishes,
Alex.
 
H

Howard Kaikow

Jonathan West said:
Hi Alex,

Use CreateObject to start a new instance of Word.Application.
Set the Visible property of that instance to False

Beware, there are gotchas involved in using an invisible instance of Word.
Take a look at this article

How to speed up Word Automation by hiding the application
http://www.word.mvps.org/FAQs/InterDev/MakeAppInvisible.htm

You will need to be very thorough about your testing.

Most importantly, where possible, use the Range object, even if Word is
visible.
 
A

Alex

Hello Jonathan,

Thanks for your reply.

Jonathan West said:
Use CreateObject to start a new instance of Word.Application.
Set the Visible property of that instance to False

I forgot to mention that I am invoking this from C++ code.

Some testing showed that #importing the correct type libraries and invoking:

Word::_ApplicationPtr pApp1(Word::CLSID_Application);

does indeed start another instance of Word, which is hidden by default (yay!)

However, coming to my 3rd requirement:

This did not work.
Double-clicking on a Word document reused the application that I started.

Is there a way of achieving this?


Best wishes,
Alex.
 
A

Alexander Nickolov

You can try with an NT service client running as a dedicated
user. This is guaranteed to run in a windowstation different
from the interactive user's windowstation. I believe Word
runs as activator (no special activation setting).

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: (e-mail address removed)
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Hello Jonathan,

Thanks for your reply.

Jonathan West said:
Use CreateObject to start a new instance of Word.Application.
Set the Visible property of that instance to False

I forgot to mention that I am invoking this from C++ code.

Some testing showed that #importing the correct type libraries and invoking:

Word::_ApplicationPtr pApp1(Word::CLSID_Application);

does indeed start another instance of Word, which is hidden by default
(yay!)

However, coming to my 3rd requirement:

This did not work.
Double-clicking on a Word document reused the application that I started.

Is there a way of achieving this?


Best wishes,
Alex.
 
P

Peter Huang [MSFT]

Hi Alex,

Based on my research, it is hard to meet the requirment 3. Because when we
double click a Doc file, it is Shell(Explorer)'s behavior about how to
invoke Winword.exe.
And If we automation Winword.exe first, and then double click the doc file,
the Winword.exe will be used to host the doc file.

Also Alexander's suggestion may be an approach.
Because word is designed as Desktop level UI interactive Application, it is
not proper to use it as a Service as you scenario that automation a
standalone version word for "private" usage.
You may take look at the KB below.

We will have consideration that host the word in Server-side environment.
Note In this context, the term "server-side" also applies to code that is
running on a Microsoft Windows NT or Microsoft Windows 2000 workstation,
provided that it is running from a WinStation other than the interactive
station of the user that is logged on. For example, code that is started by
Task Scheduler under the SYSTEM account runs in the same environment as
"server-side" ASP or DCOM code, and therefore experiences many of the same
issues. For more information on WinStations and COM, see the "More
Information" and "References" sections.

Considerations for server-side Automation of Office
http://support.microsoft.com/?id=257757

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jonathan West

Hello Jonathan,

Thanks for your reply.

Jonathan West said:
Use CreateObject to start a new instance of Word.Application.
Set the Visible property of that instance to False

I forgot to mention that I am invoking this from C++ code.

Some testing showed that #importing the correct type libraries and invoking:

Word::_ApplicationPtr pApp1(Word::CLSID_Application);

does indeed start another instance of Word, which is hidden by default
(yay!)

However, coming to my 3rd requirement:

This did not work.
Double-clicking on a Word document reused the application that I started.

Is there a way of achieving this?


Best wishes,
Alex.



Yes, take a look at this article

When users starts Word manually, they activate the instance of Word that you
previously created using CreateObject, instead of opening a new instance
http://www.word.mvps.org/FAQs/InterDev/WordUsesSameInstance.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
A

Alex

Hi Jonathan,

Jonathan West said:
Yes, take a look at this article

When users starts Word manually, they activate the instance of Word that you
previously created using CreateObject, instead of opening a new instance
http://www.word.mvps.org/FAQs/InterDev/WordUsesSameInstance.htm

Unfortunately, this did not work.

As stated in http://support.microsoft.com/?kbid=188546
"NOTE: This workaround does not work when a document is launched directly through the Windows Explorer, typically when someone double-clicks a document."
 
P

Peter Huang [MSFT]

Hi Alex,

Please check my last reply.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Alex

OK, problem half-solved.

If I run Word with the "/x" command line, it will only respond to one DDE request.
Start and stop a dummy DDE conversation with it to use up this request and presto! this instance will not be used for launching Word documents.

However, there is another snag.

While I'm safe from DDE, COM/OLE will happily use this instance.

So, is there a way to stop COM using my Word instance?


Best wishes,
Alex.
 
P

Peter Huang [MSFT]

Hi Alex,

It is hard to prevent COM to use certain Word instance.

Because when Word start up, it will register it into the ROT(Running Object
Table). So the other COM even can select to attach to certain Word Instance.
How to use Visual C# to automate a running instance of an Office program
http://support.microsoft.com/?scid=kb;en-us;316126

Here is the start up switch in Word 2003 Help file.
<quote>
/safe
Start Word in Office Safe Mode.
/ttemplatename
Start Word with a new document based on a template other than the Normal
template (Normal template: A global template that you can use for any type
of document. You can modify this template to change the default document
formatting or content.). Example: /tMyfax.dot
Note If the file name has spaces in it, enclose the complete name in
quotation marks ¡ª for example, /t"Elegant Report.dot"

Security Because templates can store macro viruses, be careful about
opening them or creating files based on new templates. Take the following
precautions: run up-to-date antivirus software on your computer, set your
macro security level to high, clear the Trust all installed add-ins and
templates check box, use digital signatures, and maintain a list of trusted
sources.

/pxslt
Start Word with a new XML document based on the specified Extensible
Stylesheet Language Transformation (XSLT) (XSL Transformation (XSLT): A
file that is used to transform XML documents into other types of documents,
such as HTML or XML. It is designed for use as part of XSL.). Example:
/p:c:\MyTransform.xsl
/a
Start Word and prevent add-ins (add-in: A supplemental program that adds
custom commands or custom features to Microsoft Office.) and global
templates (including the Normal template) from being loaded automatically.
The /a switch also locks the setting files.
/laddinpath
Start Word and then load a specific Word add-in. Example: /lSales.dll

Security Use caution when running executable files or code in macros or
applications. Executable files or code can be used to carry out actions
that might compromise the security of your computer and data.


/m
Start Word without running any AutoExec macros (macro: An action or a set
of actions that you can use to automate tasks. Macros are recorded in the
Visual Basic for Applications programming language.).
/mmacroname
Start Word and then run a specific macro. The /m switch also prevents Word
from running any AutoExec macros. Example: /mSalelead
Security Because macros can contain viruses, be careful about running
them. Take the following precautions: run up-to-date antivirus software on
your computer; set your macro security level to high; clear the Trust all
installed add-ins and templates check box; use digital signatures; maintain
a list of trusted publishers.

/n
Start a new instance of Word with no document open. Documents opened in
each instance of Word will not appear as choices in the Window menu of
other instances.
/w
Start a new instance of Word with a blank document. Documents opened in
each instance of Word will not appear as choices in the Window menu of the
other instances.

</quote>

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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