所以我设法编写了一个类,允许我访问WMI并获取有关类的信息,包括它们的方法,以及类及其后续方法的所有属性。我无法在System.Management或System.Management.Instrumentation类下的C#中找到任何内容,这些类允许我在主类或方法中访问WMI中的属性的CIM数据类型。有谁知道我可以获得这些数据类型的方式吗?
答案 0 :(得分:3)
要获取WMI类的元数据(如cimtype,value,name),可以使用PropertyData
类。
尝试使用MSDN中的示例代码
using System;
using System.Management;
public class Sample
{
public static void Main()
{
// Get the WMI class
ManagementClass osClass =
new ManagementClass("Win32_OperatingSystem");
osClass.Options.UseAmendedQualifiers = true;
// Get the Properties in the class
PropertyDataCollection properties =
osClass.Properties;
// display the Property names
Console.WriteLine("Property Name: ");
foreach (PropertyData property in properties)
{
Console.WriteLine(
"---------------------------------------");
Console.WriteLine(property.Name);
Console.WriteLine("Description: " + property.Qualifiers["Description"].Value);
Console.WriteLine();
Console.WriteLine("Type: ");
Console.WriteLine(property.Type);
Console.WriteLine();
Console.WriteLine("Qualifiers: ");
foreach(QualifierData q in
property.Qualifiers)
{
Console.WriteLine(q.Name);
}
Console.WriteLine();
foreach (ManagementObject c in osClass.GetInstances())
{
Console.WriteLine("Value: ");
Console.WriteLine(c.Properties[property.Name.ToString()].Value);
Console.WriteLine();
}
}
}