在凭据提供程序中加载 C# (COM):使用 winlogon,但在资源管理器加载它时出现问题

Load C# (COM) in a Credential Provider : working with winlogon, but problem when explorer loads it

我为 Windows 创建了一个自定义凭据提供程序。 基础 DLL 在 C++ 中,它通过 COM 接口加载 C# DLL。

    if (CoInitialize(NULL) != S_OK) {


        hr = _authenticationManager.CreateInstance("{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}");

        std::stringstream stream;
        stream << std::hex << (int)hr;
        MessageBoxA(NULL, stream.str().c_str(), "", 0);

class 是这样注册的:

REGEDIT4

[HKEY_CLASSES_ROOT\Record\{71C93A0D-861E-3195-A2D8-51DA34307BCA}.0.0.0]
"Class"="AuthenticationManager.BUTTON_TYPE"
"Assembly"="AuthenticationManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"

[HKEY_CLASSES_ROOT\AuthenticationManager.AuthenticationManager]
@="AuthenticationManager.AuthenticationManager"

[HKEY_CLASSES_ROOT\AuthenticationManager.AuthenticationManager\CLSID]
@="{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}"

[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}]
@="AuthenticationManager.AuthenticationManager"

[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="AuthenticationManager.AuthenticationManager"
"Assembly"="AuthenticationManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"

[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}\InprocServer32.0.0.0]
"Class"="AuthenticationManager.AuthenticationManager"
"Assembly"="AuthenticationManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"

[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}\ProgId]
@="AuthenticationManager.AuthenticationManager"

[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}]

C# DLL 声明如下所示:

[Guid("BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1")]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IAuthenticationManager))]
public class AuthenticationManager : IAuthenticationManager

使用 winlogon 登录计算机时,它工作完美,当我注销时,提供程序加载,C# 也一样,一切都很好

但是,当我将它用于其他目的时,它无法加载 COM 组件:CreateInstance returns 0x80040154 (REGDB_E_CLASSNOTREG).

无效的用法示例:SHIFT+右键单击 exe -> 以其他用户身份执行 提供程序已加载,但未找到 class...

我在论坛上听说混合使用 32 位和 64 位可能是问题的根源,但这两个进程(winlogon 和 explorer)都是 x64,我所有的 dll(凭据 + authenticationManager)也是 x64。

你能帮帮我吗,我已经卡了3天了....

非常感谢。

再说了,COM 不是个好主意!或者,您可以使用 Visual C++ CLI。 CLI 支持是本机 C++ 和托管 C#.NET 库之间的桥梁。