Question

How do you force a local COM server to run under a common account (local system would be good)? The RunAs documentation seems like its only for DCOM and doesnt work locally.

The problem i face is that my CoCreateInstance is being called from processes that are running in different desktops and the SCM under this scenario wants to start a new server for each desktop, I only want a single instanse - as designed!

Was it helpful?

Solution

What you are describing is a system service, not a COM server. A COM server is designed to run under whatever session runs it, not under "session 0" (services) or any single session. If you need something that only runs under 1 session and has global access to everything else, you should use a Windows Service, not a COM server.

If you need the COM server aspect for other reason, but want to share resources globally or still have "one process" that controls whatever you need to do... you can have your COM server communicate with your service using whatever IPC method you prefer.

Also, in your comments you say "when I run from the command line" -- if you run an EXE from the command-line, it doesn't matter if it is registered as a COM server or not, it just runs like any other EXE/app -- which means it runs as whatever user you run it as, in whatever session you are in. Registering an EXE as a COM server just allows other processes to run that EXE and communicate with it via OLE/COM, but the EXE can still run as a normal app as well. For example, Microsoft Word and Outlook are both COM servers. That is, outlook.exe is a COM server, but of course you can also run it as a normal application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top