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?