C# Windows Service COM exception 80080005 when starting application

扶醉桌前 提交于 2019-12-29 07:17:15

问题


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

I use the following code:

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): 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)

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".

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?


回答1:


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. Click run
  2. enter dcomcnfg
  3. Browse your way to Component services>Computers>My Computer>DComConfig>
  4. Then find your application, in my case "CATIA Application".
  5. right click>properties
  6. Go to "Identity" tab
  7. Change the user who should run this application from "The launching user" to "The interactive user".

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.

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.



来源:https://stackoverflow.com/questions/18484633/c-sharp-windows-service-com-exception-80080005-when-starting-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!