【发布时间】:2010-09-09 02:02:44
【问题描述】:
我创建了一个单独的程序集,其中包含一个旨在成为 通过 wmi 发布。然后我创建了一个 Windows 窗体应用程序 引用该程序集并尝试发布该类。当我尝试 发布课程,我得到一个类型的异常 System.Management.Instrumentation.WmiProviderInstallationException。这 异常消息显示“类型异常 'System.Management.Instrumentation.WMIInfraException' 被抛出。”。我有 不知道这意味着什么。我已经尝试过 .Net2.0 和 .Net3.5(也是 sp1)并得到相同的结果。
下面是我的 wmi 类,后面是我用来发布它的代码。
//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());
}
【问题讨论】:
标签: c# .net .net-3.5 .net-2.0 wmi