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?
Asked
Active
Viewed 1,641 times
0
-
[CIM_DataFile Class WMI](http://msdn.microsoft.com/en-us/library/aa387236%28v=vs.85%29.aspx) – MethodMan Nov 25 '14 at 19:34
-
Nothing in there seems to allow me to get the data types of properties in WMI classes. Also, the CIM_DataFile doesn't seem to sit at the top of the hierarchy for the classes I'm looking into. I'm not yet an expert with WMI/CIM/WBEM, but I'm pretty sure this isn't what I'm looking for. – Christopher D Albert Nov 25 '14 at 19:39
1 Answers
3
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();
}
}
}

RRUZ
- 134,889
- 20
- 356
- 483
-
Thanks, this worked. I thought it was the Properties property of the ManagementClass object, but I was having a hard time using the data contained within. Still new to the System.Management namespace. Thanks again! Edit: – Christopher D Albert Nov 28 '14 at 18:09