Reputation: 599
I'm trying to list all of the available fields on a WMI Class using C#.
The closest I've got is listing all of the available equivalent of tables in WMI
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from meta_class");
foreach (ManagementClass wmiClass in searcher.Get())
{
Console.WriteLine(wmiClass["__CLASS"].ToString());
}
However it appears there is no equivalent of this for the fields.
Is this possible or is it just a case of looking up the reference manual to see all of the available fields?
Upvotes: 4
Views: 2883
Reputation: 109100
If you have an instance of the WMI class, then System.Management.ManagementBaseObject.Properties
is a listing of all the properties (WMI doesn't separate properties and fields – being based on COM they're all properties).
ManagementClass
derives from ManagementBaseObject
so it also has a Properties
property listing the properties of the WMI class, so to list all the properties:
var wmiClass = new ManagementClass("Win32_ComputerSystem");
foreach (var prop in wmiClass.Properties) {
Console.WriteLine(prop.Name);
}
(Each element of the Properties
collection is a PropertyData
instance with lots of information about each property.)
Upvotes: 8