Search code examples
c#processcomwindows-services.net-6.0

.NET 6.0 application fails to use COM object when launched from Windows service after user logs out


I'm developing an application in .NET 6.0 that needs to use a COM object (which is a strict requirement). I now need to schedule and launch this application through a job scheduling service.

I considered creating a Windows service to handle the job because it provides useful features like automatically restarting the service if it crashes, ensuring better business continuity.

However, I encountered an issue: when the application is launched by the service using Process.Start(), it fails to access the COM object due to authorization issues.

Details:

  • Initially, the application couldn't access the COM object at all.
  • I then modified the COM object's security and identity settings in Component Service (DCOMCNFG.exe)
  • As a result, the application now works correctly, but only when I'm logged in to the machine (via RDS)
  • However, once I log out, the service continues running, but the spawned application loses access to the COM object
  • I also tried running the service under a specific User account instead of Local System, but this didn't resolve the issue

My questions:

  1. Is using a Windows service the right approach for this scenario?
  2. If yes, how can I ensure that the spawned application retains authorization to use the COM object, even when no user is logged in?

Any guidance or suggestions on how to resolve this issue would be greatly appreciated!


Solution

  • I solved the problem. My problem was that the COM Object "Identity" property was setted on "Interactive user", so obviously when i disconnected from the session it ceased to work. My solution was to set a specific user and run the Service under that user. Thanks for your answer.