Skip to content

Windows ComHost COM registration in HKCU instead of HKLM? #45750

@smourier

Description

@smourier

As far as I know, currently, to register a COM object written in .NET 5 (or .NET Core 3.x for that matter) we need to

"Open an elevated command prompt and run regsvr32 ProjectName.comhost.dll. That will register all of your exposed .NET objects with COM." from here

https://docs.microsoft.com/en-us/dotnet/core/native-interop/expose-components-to-com#register-the-com-host-for-com

I think the relevant source is here: https://github.com/dotnet/runtime/blob/master/src/installer/corehost/cli/comhost/comhost.cpp#L309 it seems pretty much hardcoded for HKEY_LOCAL_MACHINE.

As you know, registering COM component in HKCU (HKEY_CURRENT_USER\SOFTWARE\Classes\CLSID for the CLSID, etc.) is pretty common and supported by "COM" in general (CoCreateInstance, etc.). It's also supported by tooling such as Visual Studio's ATL and Windows' regsvr32.exe with the help of DllInstall (optional) DLL export:

https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-dllinstall

It has the enormous advantage of avoiding elevated rights for setup, installers, etc.

Can support for this be added to comhost?

In the meantime, is there any way to do this with current .NET 5? Should I write a custom comhost? How?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions