微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我为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);

该类是这样注册的:

REGEDIT4

[HKEY_CLASSES_ROOT\Record\{71C93A0D-861E-3195-A2D8-51DA34307BCA}\1.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,PublicKeyToken=null"
"RuntimeVersion"="v4.0.30319"

[HKEY_CLASSES_ROOT\CLSID\{BAF984BD-0D41-42D1-AA49-4BC98EE6C4A1}\InprocServer32\1.0.0.0]
"Class"="AuthenticationManager.AuthenticationManager"
"Assembly"="AuthenticationManager,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返回0x80040154(REGDB_E_CLASSNOTREG)。

无法使用的用法示例:在exe上按SHIFT +右键单击->以其他用户身份执行 提供程序已加载,但找不到该类...

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

您能帮我吗,我被困了三天....

非常感谢您。

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。