如何在 .NET 中使用 MSAdminBase COM 对象?

发布于 2024-11-23 20:38:01 字数 938 浏览 0 评论 0原文

该对象在 %windir%\system32\ADMWPROX.DLL 中实现 - 请参阅 HKEY_CLASSES_ROOT\CLSID\{70B51430-B6CA-11D0-B9B9-00A0C922E750}

它完全可以从C 代码,但我希望将其替换为 .NET 代码,这真是太糟糕了 - ADMWPROX.DLL 没有作为 tlbimp 的有效类型库出现:

z:\Work>tlbimp c:\Windows\system32\admwprox.dll
Microsoft (R) .NET Framework Type Library to Assembly Converter 4.0.30319.1
Copyright (C) Microsoft Corporation.  All rights reserved.

TlbImp : error TI1002 : The input file 'c:\Windows\system32\admwprox.dll' is not a valid type library.

z:\Work>

当然,在 Visual Studio 中添加 COM 引用时,COM 对象列表中缺少它。

PS:我正在尝试设置 IIS://localhost/W3SVC/1!SslCertHash 属性和 本文解释说,唯一的方法是通过 MSAdminBase 对象,而不是 MSAdminObject (由于架构定义中的错误) )。后者可以方便地由 .NET System.DirectoryServices.DirectoryEntry 包装,但前者不是 - 因此是我的痛苦。

This object is implemented in %windir%\system32\ADMWPROX.DLL - see HKEY_CLASSES_ROOT\CLSID\{70B51430-B6CA-11D0-B9B9-00A0C922E750}

It is perfectly usable from C code, but I wish to replace it with a .NET code and what a bummer - ADMWPROX.DLL does not appear as a valid type library to tlbimp:

z:\Work>tlbimp c:\Windows\system32\admwprox.dll
Microsoft (R) .NET Framework Type Library to Assembly Converter 4.0.30319.1
Copyright (C) Microsoft Corporation.  All rights reserved.

TlbImp : error TI1002 : The input file 'c:\Windows\system32\admwprox.dll' is not a valid type library.

z:\Work>

And of course, it is missing from the list of COM objects when adding a COM reference in Visual Studio.

PS: I am trying to set the IIS://localhost/W3SVC/1!SslCertHash property and this article explains that the only way to do it is through the MSAdminBase object, rather than MSAdminObject (due to a bug in the schema definition). The latter is conveniently wrapped by the .NET System.DirectoryServices.DirectoryEntry, but the former is not - hence is my pain.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

西瑶 2024-11-30 20:38:01

好的,我是这样做的:

  1. 将 IMSAdminBase_W 接口定义转换为 IDL。该接口在 Microsoft SDK 的 iadmw.h 中声明。它包含注释中的所有 IDL 属性,因此转换很容易。当然,IDL 还需要声明组件类和库。
  2. 然后我用 midl 编译了 IDL 文件。
  3. 接下来,我对生成的 tlb 文件运行 tlbimp。
  4. 最后,必须修复生成的互操作 dll,特别是 TlbImp 将结构归因于 StructLayout.Pack = 4,如果 .NET 以 64 位运行,这将使我们失败 - 请参阅 传递字节时 inetinfo.exe 内部发生访问冲突通过 IMSAdminBase 从编译到 AnyCPU 的 .NET 应用程序获取数组。我使用Reflector.NET对其进行反编译。事实上,我只是将反编译的互操作源代码包含在我的项目中。

就是这样。

我没有创建互操作源代码作为第一步也是唯一的一步,因为 IMSAdminBase_W 接口相当大,所以我更愿意将其转换为 IDL,这样更容易。

OK, here is how I did it:

  1. Converted the IMSAdminBase_W interface definition to IDL. The interface is declared in iadmw.h from the Microsoft SDK. It contains all the IDL attributes inside comments, so the conversion is easy. Of course, the IDL needs to declare the coclass and the library as well.
  2. Then I compiled the IDL file with midl.
  3. Next, I ran tlbimp on the resulting tlb file.
  4. Finally, the produced interop dll had to be fixed, specifically TlbImp attributed the structures with the StructLayout.Pack = 4, which will fail us if the .NET runs as 64 bits - see Access Violation inside inetinfo.exe when passing byte array through IMSAdminBase from a .NET app compiled to AnyCPU. I used Reflector.NET to decompile it. In fact, I then just included the decompiled interop source as part of my project.

That's it.

I did not create the interop source code as the first and only step, because the IMSAdminBase_W interface is quite large, so I preferred to convert it to IDL, which was easier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文