I've created a seperate assembly with a class that is intended to be published through wmi. Then I've created a windows forms app that references that assembly and attempts to publish the class. When I try to publish the class, I get an exception of type System.Management.Instrumentation.WmiProviderInstallationException. The message of the exception says "Exception of type 'System.Management.Instrumentation.WMIInfraException' was thrown.". I have no idea what this means. I've tried .Net2.0 and .Net3.5 (sp1 too) and get the same results.
Below is my wmi class, followed by the code I used to publish it.
//Interface.cs in assembly WMI.Interface.dll
using System;
using System.Collections.Generic;
using System.Text;
[assembly: System.Management.Instrumentation.WmiConfiguration(@"root\Test",
HostingModel =
System.Management.Instrumentation.ManagementHostingModel.Decoupled)]
namespace WMI
{
[System.ComponentModel.RunInstaller(true)]
public class MyApplicationManagementInstaller :
System.Management.Instrumentation.DefaultManagementInstaller { }
[System.Management.Instrumentation.ManagementEntity(Singleton = true)]
[System.Management.Instrumentation.ManagementQualifier("Description",
Value = "Obtain processor information.")]
public class Interface
{
[System.Management.Instrumentation.ManagementBind]
public Interface()
{
}
[System.Management.Instrumentation.ManagementProbe]
[System.Management.Instrumentation.ManagementQualifier("Descriiption",
Value="The number of processors.")]
public int ProcessorCount
{
get { return Environment.ProcessorCount; }
}
}
}
//Button click in windows forms application to publish class
try
{
System.Management.Instrumentation.InstrumentationManager.Publish(new
WMI.Interface());
}
catch (System.Management.Instrumentation.InstrumentationException
exInstrumentation)
{
MessageBox.Show(exInstrumentation.ToString());
}
catch (System.Management.Instrumentation.WmiProviderInstallationException
exProvider)
{
MessageBox.Show(exProvider.ToString());
}
catch (Exception exPublish)
{
MessageBox.Show(exPublish.ToString());
}