How to start new word instance without add-ins when word is already started

0

I am using Word (from 2007 to 2013) to convert documents to PDFA format, and i'm having trouble with users who have certain add-ins. When they use the system they get an assortment of COM Exceptions like RPC_E_SERVERCALL_RETRYLATER and (0x800706BA) RPC server unavailable.

If they disable the add-ins it works fine. Problem is that the add-ins are required so that simple solution is out the window. (Also I know that using word for this kind of thing is frowned upon, and we are looking into getting something better, but until the business side want's to pay, we are stuck with this)

The new plan is to start word with the /a parameter to make it start without add-ins.

I have seen another question How can I start MS Office Word from .NET without Add-ins? Where there is a working solution for one instance of Word,

 //startup without plugins
        System.Diagnostics.Process.Start(
            @"Winword.exe",
            @"/a");
        //give a time for startup
        Thread.Sleep(2000);
        //attach to office
        Application officeApplication = (Application)Marshal.GetActiveObject("Word.Application");

My question is two fold: Is it possible to set startup parameters when you start word like this

var _word = new Word.Application();

So I don't have to use Process.start();

And if not, how do I do a late bind to a specific word instance (GetActiveObject(), always gets the oldest word instance), perhaps there is some other method?

c#
office-interop
com-interop
asked on Stack Overflow May 7, 2016 by Martin • edited May 23, 2017 by Community

1 Answer

0

To your first question, there's no way to pass parameters or otherwise influence how Word starts when using the new keyword. The instructions for starting the application are in the Registry, so it would involve changing how the new keyword is implemented in the Registry. And since this Registry entry also determines how Windows Explorer starts the Word.Application, changing the Registry entry would also change the way Word works for the user.

It is possible to unload add-ins after an instance of Word has started via the Application.COMAddins property. This is the equivalent of unchecking the boxes next to the Add-in entries in the COM Add-ins dialog box in the Word UI. I would test whether doing this in the UI allows your software to work properly.

If it does, you can incorporate this in your code - no need to worry about starting Word without the add-ins.

Which brings us to the second question: GetActiveObject is only able to access the single instance of Word (any Office application) registered in the ROT. By design, Office applications register only a single instance in the ROT and usually, this will be the first instance. There are a couple of KB articles on MSDN that describe this. The only work-around is to start two instances of Word in the user profile, "hiding" the first (the registered) one and presenting the second to the user.

But this can be tricky, so if it works, I'd go with the suggestion about the COMAddins collection to unload the problem Add-ins.

(I'm currently on a mobile device. Next time I'm on my main machine I'll try to remember to paste in the links to the KB articles on the ROT.)

answered on Stack Overflow May 9, 2016 by Cindy Meister

User contributions licensed under CC BY-SA 3.0