启动应用程序时 C# Windows 服务 COM 异常 80080005 [英] C# Windows Service COM exception 80080005 when starting application

查看:28
本文介绍了启动应用程序时 C# Windows 服务 COM 异常 80080005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个尝试启动应用程序的 Windows 服务(在本例中为 CATIA).

I have created a Windows Service that try to start an application (in this case CATIA).

我使用以下代码:

private Application GetApplicationObject(string ProgId)
        {
            Application AppObject = null;
            //Try to get allready open instance of the Application
            try
            {
                AppObject = (Application)Marshal.GetActiveObject(ProgId);
            }
            catch
            {
                //Create a new instance of the Application instead
                AppObject = (Application)Activator.CreateInstance(Type.GetTypeFromProgID(ProgId));                
            }
            return AppObject;
        } 

当我的服务尝试启动应用程序时出现以下错误:

I get the following error when my Service try to start the application:

System.Runtime.InteropServices.COMException (0x80080005):检索具有 CLSID 的组件的 COM 类工厂{87FD6F40-E252-11D5-8040-0010B5FA1031}由于以下原因失败错误:80080005.在System.RuntimeTypeHandle.CreateInstance(RuntimeType type, BooleanpublicOnly, Boolean noCheck, Boolean&可以缓存,RuntimeMethodHandle&ctor, Boolean&bNeedSecurityCheck) 在System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, BooleanfillCache) 在 System.RuntimeType.CreateInstanceImpl(BooleanpublicOnly, Boolean skipVisibilityChecks, Boolean fillCache) atSystem.Activator.CreateInstance(Type type, Boolean nonPublic) atCATIA.CATIA.GetApplicationObject(String ProgId)

System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {87FD6F40-E252-11D5-8040-0010B5FA1031} failed due to the following error: 80080005. at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at CATIA.CATIA.GetApplicationObject(String ProgId)

重要提示:当我将此代码作为 Windows 应用程序而不是 Windows 服务运行时,一切正常.我还尝试先启动 CATIA 并让它在后台运行,但我的服务无法捕获它.

Important: When I run this code as a Windows application instead of a Windows service everything works fine. I also tried to start CATIA first and have it running in the background, but my Service are not able to catch it.

我使用本地系统运行服务,并且选中了与桌面交互"框.

I run the Service with Local System, and I have checked the box "Interact with desktop".

我的 ProgId 是 CATIA.Application,正如我所说,当我将它作为应用程序而不是服务运行时它可以工作.

My ProgId is CATIA.Application, and as I said it works when I run it as an application instead of a service.

知道是什么原因造成的吗?

Any idea of what is causing this?

推荐答案

我现在找到了解决方案.

I have now found a solution.

我在另一个论坛上找到了它,那里有人在通过网络运行另一个应用程序时遇到问题.奇怪的是,这个解决方案也适用于我.

I found it in another forum, where someone had problem to run another application through web. Strangely enough, that solution worked for me too.

  1. 点击运行
  2. 输入 dcomcnfg
  3. 浏览组件服务>计算机>我的电脑>DComConfig>
  4. 然后找到您的应用程序,在我的例子中是CATIA 应用程序".
  5. 右键单击>属性
  6. 转到身份"标签
  7. 将应该运行此应用程序的用户从启动用户"更改为交互式用户".

现在它对我有用.如果我先手动启动它,我仍然无法捕获该进程 (GetActiveObject).但至少服务设法启动了一个新实例而没有任何错误.

Now it works for me. I am still not able to catch the process (GetActiveObject) if I start it manually first. But at least the Service manage to start a new instance without any errors.

我认为这对许多在尝试从 Windows 服务启动应用程序时遇到此错误消息的人会有所帮助.

I think this can be helpful for a lot of people who come across this error message when trying to start an application from a Windows Service.

这篇关于启动应用程序时 C# Windows 服务 COM 异常 80080005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆