Reputation: 57
So I've managed to write a class that allows me to access WMI and get information about classes, including their methods, and all of the properties of the classes and of their subsequent methods. I am unable to find anything in C# under the System.Management or System.Management.Instrumentation classes that allows me to access the CIM data types of properties in WMI, either in the main class, or in methods. Does anyone know of a way that I can get those data types?
Upvotes: 0
Views: 1825
Reputation: 136431
To get the metadata (like cimtype, value, name) of the WMI classes you can use the PropertyData
class.
Try this sample code from 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();
}
}
}
Upvotes: 3