访问自定义 WMI 提供程序无限期挂起
我正在尝试用 C# 编写一个自定义的解耦 WMI 提供程序。我已经遵循了这些示例,但是每当我尝试从 WMI Studio、通过 PowerShell 或通过 wmic 访问我的 WMI 类时,它就会无限期地挂在那里,直到我终止提供程序主机应用程序,此时我收到的错误范围从“无效类”到“远程过程调用失败”。
如果我不尝试实际访问 WMI 提供程序的实例,我可以看到它正常,因此我知道它正在向 WMI 注册。
这是我正在运行的代码:
[assembly: WmiConfiguration(@"root\CIMV2", HostingModel=ManagementHostingModel.Decoupled)] [RunInstaller(true)] public class WmiInstaller : DefaultManagementInstaller { } [ManagementEntity(Singleton=true)] [ManagementQualifier("Description", Value="Accesses and manipulates licenses held in the SLN license database.")] public class SoftwareLicensingNetworkLicenseDatabase { [ManagementBind] public SoftwareLicensingNetworkLicenseDatabase() { Test = "OMG!"; } [ManagementProbe] public string Test; }
然后在我的 main 函数中:
[STAThread] static void Main() { InstrumentationManager.RegisterType(typeof(SoftwareLicensingNetworkLicenseDatabase)); Console.ReadLine(); InstrumentationManager.UnregisterType(typeof(SoftwareLicensingNetworkLicenseDatabase)); }
我尝试了多种方法来诊断此问题:切换到 .Net 3.5(我正在使用 .Net 4.0),更改名称空间名称,使用多实例类而不是单例类等。
任何帮助将不胜感激!
I'm trying to write a custom decoupled WMI provider in C#. I've followed the examples and yet whenever I try to access my WMI class from either WMI Studio, through PowerShell, or via wmic, it just hangs there indefinitely until I terminate the provider host app, at which point I get an error ranging from "Invalid Class" to "The remote procedure call failed".
I can see my WMI provider fine if I don't try to actually access an instance of it, so I know it's registering with WMI.
Here's the code I'm running:
[assembly: WmiConfiguration(@"root\CIMV2", HostingModel=ManagementHostingModel.Decoupled)] [RunInstaller(true)] public class WmiInstaller : DefaultManagementInstaller { } [ManagementEntity(Singleton=true)] [ManagementQualifier("Description", Value="Accesses and manipulates licenses held in the SLN license database.")] public class SoftwareLicensingNetworkLicenseDatabase { [ManagementBind] public SoftwareLicensingNetworkLicenseDatabase() { Test = "OMG!"; } [ManagementProbe] public string Test; }
And then in my main function:
[STAThread] static void Main() { InstrumentationManager.RegisterType(typeof(SoftwareLicensingNetworkLicenseDatabase)); Console.ReadLine(); InstrumentationManager.UnregisterType(typeof(SoftwareLicensingNetworkLicenseDatabase)); }
I've tried any number of things to diagnose this issue: switch to .Net 3.5 (I'm using .Net 4.0), change namespace names, use a multi-instance class instead of a singleton, etc.
Any help would be sincerely appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,我发现了:
您的
Main
函数不能将STAThread
作为属性。我在调试需要它的东西时添加了它并且没有将其取下。它认为,一旦你思考一下,我就会花很长时间才能弄清楚如此简单和明显的事情。Nevermind, I figured it out:
Your
Main
function cannot haveSTAThread
as an attribute. I added it when I was debugging something that required it and had not taken it off. It figures it would take me so long to figure out something so simple and obvious once you think about it.