开发者

Accessing custom WMI provider hangs indefinitely

开发者 https://www.devze.com 2023-01-06 05:50 出处:网络
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 ha

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!


Nevermind, I figured it out:

Your Main function cannot have STAThread 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消