System.UnauthorizedAccessException:创建COM组件的实例失败,错误80070005(C#)

时间:2015-10-03 20:52:45

标签: c# node.js windows com windows-services

我遇到了C#.NET命令行应用程序的问题,其主要思想是使用COM对象从其他程序获取数据。手动执行或在Node.js服务器中作为子进程运行时,它工作正常,但是当整个项目作为Windows服务安装时,C#应用程序响应以下错误:

System.UnauthorizedAccessException: Creating an instance of the COM component with CLSID {D64DB4A9-3B26-4D2B-B556-9DA433C54175} from the IClassFactory failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
   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)
   at CurrentCamUri.Program.Main(String[] args)

从我读到的here以及主要关注Office应用程序的类似线程,我应该在dcomcnfg /32中的“DCOM Config”标签中看到COM对象,但是我找不到任何与相关的CLSID。我尝试在没有'/ 32'后缀的情况下运行dcomcnfg但也没有成功。我需要从中获取数据的主要应用程序是32位(让我们称之为母版应用程序)。

有任何建议我该如何解决这个问题?我真的很感激。谢谢!

1 个答案:

答案 0 :(得分:1)

确保Windows服务在具有访问COM组件权限的帐户下运行。

您可以通过启动regedt32.exe来检查这些权限,转到HKCR \ CLSID {D64DB4A9-3B26-4D2B-B556-9DA433C54175},右键单击并选择“权限...”。