Search code examples
winapicomregistryatldcom

Registering COM class to run as a service


I'm developing a DCOM application that should run as a service. I've managed to make this app work as a standalone app (the client requests the component, and OS starts the standalone app) - to do it, I'm executing MyApp.exe /regserver But after I run MyApp.exe /service the client can't reach the app - neither when the service is not running, nor when it is running. The client is not developed by me (actually, that's Excel RTD function), so I can't check at what step the problem is happening. So, how should I register a class/app so that it runs as a service? Developed in VS2013, created ATL project "service exe".


Solution

  • COM registration for service ATL project is very much similar to its application mode: the same registry keys for COM classes with the only difference that the server is hosted by service. More important for you however is that clients access service COM objects across session boundary, and with different credentials. YourApp.exe is running as service logged on as Local System (unless you changed it manually or tweaked COM registration code), whereas clients are logged on as users.

    Making it a service, make sure to review Launch and Activation Permissions for your COM objects. For troubleshooting, you might also want to change user account for your service to match user running the client application (to rule out problems related to permissions and different user accounts).