winapicomout-of-process

How to tell if a local server process was launched by COM?


I have an application which supports out-of-process COM automation. Now, I want it to be able to behave differently when it is launched by user and when it is started by COM to serve an automation request. How can I distinguish these cases from within the application?

Googling has brought me nothing, and the only idea I have so far is to determine the parent process, but I'm not sure how fragile it would be.


Solution

  • When COM launches local out-of-process server, it looks up registry for the hosting process path and appends "-Embedding" command line parameter. This is where you are supposed to look at to, respectively, detect COM launch.

    The behavior is documented here:

    COM appends the "-Embedding" flag to the string, so the application that uses flags needs to parse the whole string and check for the -Embedding flag.