我有一个使用Word Interop的应用程序
Microsoft.Office.Interop.Word.Application word = null;
word = new Microsoft.Office.Interop.Word.Application();
//word.ReadFile
//word.SaveAs
它在我们的一台服务器上工作正常,但我们最近又买了一台。新服务器安装了Office Professional Plus 2016中的Word(没有其他应用程序,如Excel或其他)。 在新服务器上,我可以从我的帐户运行此应用程序(这告诉我机器上存在所有组件)。
但是,如果从服务帐户运行应用程序,则会获得
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
这看起来像访问问题,但我无法确定哪个特定的权限服务帐户丢失。 试图调试这种情况我甚至给了服务帐户管理员访问权限,但它没有解决问题。
非常感谢任何想法或建议!
P.S。是的我知道MS不推荐它,但是之前我在许多项目中使用Office Automation成功,而且这个特定的应用程序正在另一台机器上运行。 我希望找到解决这个问题的方法。
答案 0 :(得分:0)
this thread 帮助我找到了部分解决方案。 在我的情况下,它使用DCOMCNFG.exe打开它并转到组件服务 - &gt;计算机 - &gt;我的电脑 - &gt; DCOM配置 - &gt; Office许可COM服务器16 - &gt;属性 - &gt;安全性 - >启动和激活权限 - >选择自定义并单击编辑,然后添加将以完全访问权限运行您的应用程序的用户< / p>
不幸的是,这只是部分解决方案。我可以&#34;运行AS&#34;我的应用程序现在,但在任务计划程序上设置它会得到相同的错误。我一直在寻找......
答案 1 :(得分:0)
Microsoft目前不建议也不支持从任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务)自动化Microsoft Office应用程序,因为Office可能会出现不稳定Office在此环境中运行时的行为和/或死锁。
如果要构建在服务器端上下文中运行的解决方案,则应尝试使用已为安全无人值守执行的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方法。如果从服务器端解决方案使用Office应用程序,则应用程序将缺少许多成功运行的必要功能。此外,您将承担整体解决方案稳定性的风险。请在Considerations for server-side Automation of Office文章中详细了解相关内容。
如果仅处理开放XML文档,请考虑使用Open XML SDK,有关详细信息,请参阅Welcome to the Open XML SDK 2.5 for Office。或者只是尝试使用为服务器端执行而设计的任何第三方组件组件。