TL;DR - How do I prevent -Embedding
startup of a CLSCTX_LOCAL_SERVER
server? Preferably so that the clients get a decent error code immediately.
Background
We have a native C++ interactive Desktop application that interacts with a COM object in another native C++ interactive Desktop application.
Basically, COM is used as an interprocess communication mechanism.
Now, when the "server" application is started interactively after the user has brought it into the correct state, it will prepare the COM interface: CoRegisterClassObject
etc etc.
When the client application is used and then does it's CoCreateInstance
for the coclass, it will communicate with the already running other Desktop application, which is what is intended.
However, when the "server" application is not running, starting the client will launch the server application interactively, which is NOT what we want, because it needs quite some processing and setting up before the client can meaningfully communicate with it.
Question
So, what would make more sense is for the client to just error out in case the server is not running, instead of having the COM infrastructure start an interactive application that can't service the request meaningfully anyways.
We've toyed around with the following ideas:
- Unregister the server each time it is closed.
- It seems this won't work, as we need administrative rights to register/unregister the server.
- Use the
CLSCTX_DISABLE_AAA
flag on the client side.- This seems to work, if the client specifies this and the server ain't running, it will get
0x80070005 ERROR_ACCESS_DENIED
, but we're rather unsure whether this is the correct approach.
- This seems to work, if the client specifies this and the server ain't running, it will get
- Do an early check in the server application to detect the
-Embedding
switch and immediately exit the application on this.- The client application will run into a timeout (~ 2 min), which is not very user friendly.
- from comments Do not write the info to the registry -
CoRegisterClassObject
should be enough.- Currently, I have:
HKCR\AppID (...)
HKCR\CLSID\{...}
plus subkeysProgID
,VersionIndependentProgID
,LocalServer32
,Typelib
- Clients currently resolve the CLSID from the VersionIndependentProgID
- So I'm left wondering which parts of the registry are really optional.
- Currently, I have:
Is there any "standard" way to prevent COM local server executable activation for a given registered COM class?
CoRegisterClassObject
client get errorREGDB_E_CLASSNOTREG
, otherwice callCoRegisterClassObject
is enouth – RbMm