我有一个使用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)这看起来像是访问问题,但我不能确定缺少哪个特定的权限服务帐户。尝试调试这种情况时,我甚至授予了服务帐户管理员访问权限,但这并没有解决问题。
如有任何想法或建议,我们将不胜感激!
附注:是的,我知道微软不推荐它,但是我之前在很多项目中成功地使用了Office Automation,而且这个特定的应用程序在另一台机器上也可以工作。我希望能找到解决这个问题的办法。
发布于 2017-07-21 06:42:07
this thread帮助我找到了部分解决方案。在我使用DCOMCNFG.exe的情况下,打开它并转到组件服务->计算机->我的电脑->DCOM配置-> Office Licensing COM Server16->属性->安全->启动和激活权限->选择自定义,然后单击编辑并添加将以完全访问权限运行您的应用程序的用户
不幸的是,这只是部分解决方案。我现在可以“运行”我的应用程序,但是当在Task Scheduler上设置时,它得到相同的错误。我一直在找..。
发布于 2017-08-07 19:59:28
微软目前不建议也不支持从任何无人参与的、非交互的客户端应用程序或组件(包括ASP.NET和NT服务)自动化Microsoft Office应用程序,因为当Office在此环境中运行时,它可能表现出不稳定的行为和/或死锁。
如果要生成在服务器端上下文中运行的解决方案,则应尝试使用已设置为可无人参与执行的安全组件。或者,您应该尝试找到至少允许部分代码在客户端运行的替代方案。如果从服务器端解决方案使用Office应用程序,则该应用程序将缺少成功运行所需的许多功能。此外,您将在整体解决方案的稳定性方面承担风险。在Considerations for server-side Automation of Office文章中阅读更多关于这方面的内容。
如果只处理open Open XML SDK文档,请考虑使用Welcome to the Open XML SDK 2.5 for Office获取更多信息。或者只是尝试使用为服务器端执行而设计的任何第三方组件组件。
https://stackoverflow.com/questions/45193945
复制相似问题