我正在尝试在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; }
然后在我的主函数中:
[STAThread] static void Main() { InstrumentationManager.RegisterType(typeof(SoftwareLicensingNetworkLicenseDatabase)); Console.ReadLine(); InstrumentationManager.UnregisterType(typeof(SoftwareLicensingNetworkLicenseDatabase)); }
我已经尝试了很多东西来诊断这个问题:切换到.Net 3.5(我正在使用.Net 4.0),更改命名空间名称,使用多实例类而不是单例等等。
真诚地感谢任何帮助!
答案 0 :(得分:1)
没关系,我明白了:
您的Main
函数无法将STAThread
作为属性。当我调试需要它并且没有取下它的东西时,我添加了它。它认为,一旦你想到它,我会花很长时间才能弄清楚这么简单明了的东西。