forderud / ComSamples

Examples of language-neutral COM interfaces for IPC and language interop.
MIT License
1 stars 2 forks source link

Support "reg-free" MyServer mode #8

Closed forderud closed 1 year ago

forderud commented 1 year ago

Motivation: Want to support deployments where MyServer is running in a background service that is auto-started at system bootup.

Tasks:

  1. Move TypeLib registration to MyServer startup, so that prior COM registration can be skipped.
  2. Add AppID registration and register HKCR\AppID\{APPID}\RunAs = "Interactive User"
  3. Call CoInitializeSecurity to allow non-elevated clients to connect. example

Tested configurations

Setup Non-elevated client Elevated client
Non-elevated server TypeLib registration failure (can probably be worked around with RegisterTypeLibForUser) N/A
Elevated server CoGetClassObject failure: Class not registered (0x80040154) Works nicely 👍

Background information

COM security

Microsoft ATL reference impl

Extract from atlbase.h (with inlining of parameters):

CoRegisterClassObject(*pclsid, p, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED, &pCache->dwRegister);
...
CoResumeClassObjects();

TypeLib registration

LoadTypeLibEx(tlbPath, REGKIND_REGISTER, ...) seem to fail silently if not running with admin privileges.

Links:

Links

forderud commented 1 year ago

Support for manually started server processes was introduced in 775ed376df895924185386fe18901d3fa307d8de . I think that will be sufficient for this project.