Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top