2
我想在C#中编写自定义分离WMI提供程序。我遵循这些示例,但是每当我尝试从WMI Studio或PowerShell访问WMI类,或者通过wmic访问我的WMI类时,它都会无限期地挂在那里,直到我终止提供程序主机应用程序,此时出现错误范围从“无效的类”到“远程过程调用失败”。访问自定义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),更改命名空间名称,使用多实例类而不是单例,等等。
任何帮助都会是sincerel Ÿ赞赏!