简体   繁体   English

当单词已经启动时,如何在没有加载项的情况下启动新单词实例

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

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. 我正在使用Word(从2007年到2013年)将文档转换为PDFA格式,但是遇到具有某些加载项的用户时遇到了麻烦。 When they use the system they get an assortment of COM Exceptions like RPC_E_SERVERCALL_RETRYLATER and (0x800706BA) RPC server unavailable. 当他们使用系统时,会得到各种COM异常,例如RPC_E_SERVERCALL_RETRYLATER和(0x800706BA)RPC服务器不可用。

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. 新计划是使用/ a参数开头word,以使其在没有加载项的情况下开始。

I have seen another question How can I start MS Office Word from .NET without Add-ins? 我看到了另一个问题, 如何在没有外接程序的情况下从.NET启动MS Office Word? Where there is a working solution for one instance of Word, 如果有一个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(); 因此,我不必使用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? 如果不是,我该如何后期绑定到特定的单词实例(GetActiveObject(),始终获取最早的单词实例),也许还有其他方法?

To your first question, there's no way to pass parameters or otherwise influence how Word starts when using the new keyword. 对于第一个问题,没有办法传递参数或以其他方式影响使用new关键字时Word的启动方式。 The instructions for starting the application are in the Registry, so it would involve changing how the new keyword is implemented in the Registry. 启动应用程序的说明位于注册表中,因此它将涉及更改在注册表中实现new关键字的方式。 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. 并且由于此注册表项还确定Windows资源管理器如何启动Word.Application,因此更改注册表项也将更改Word为用户工作的方式。

It is possible to unload add-ins after an instance of Word has started via the Application.COMAddins property. 通过Application.COMAddins属性启动Word实例后,可以卸载加载项。 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. 这等效于在Word UI中取消选中“ COM加载项”对话框中“加载项”旁边的框。 I would test whether doing this in the UI allows your software to work properly. 我将测试在UI中执行此操作是否允许您的软件正常工作。

If it does, you can incorporate this in your code - no need to worry about starting Word without the add-ins. 如果是这样,您可以将其合并到您的代码中-无需担心在没有加载项的情况下启动Word。

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. 这就GetActiveObject了第二个问题: GetActiveObject仅能访问在ROT中注册的Word(任何Office应用程序)的单个实例。 By design, Office applications register only a single instance in the ROT and usually, this will be the first instance. 根据设计,Office应用程序仅在ROT中注册一个实例,通常,这将是第一个实例。 There are a couple of KB articles on MSDN that describe this. MSDN上有一些知识库文章对此进行了描述。 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. 唯一的解决方法是在用户配置文件中启动Word的两个实例,“隐藏”第一个(已注册的)实例,然后将第二个实例呈现给用户。

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. 但这可能很棘手,因此,如果可行,我会建议使用COMAddins集合来卸载有问题的加载项。

(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.) (我目前在移动设备上。下次,在我的主机上,我将尝试记住粘贴指向ROT上KB文章的链接。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM