WMI lists schema information in .NET.

I am trying to list all available fields in a WMI class using C #.

The closest I have is listing all the available table equivalents in WMI

ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from meta_class"); foreach (ManagementClass wmiClass in searcher.Get()) { Console.WriteLine(wmiClass["__CLASS"].ToString()); } 

However, there seems to be no equivalent for fields.

Is this possible or is it just looking for a reference guide to view all the available fields?

+4
source share
1 answer

If you have an instance of the WMI class, System.Management.ManagementBaseObject.Properties is a list of all properties (WMI does not separate properties and fields - based on COM, they are all properties).

ManagementClass comes from ManagementBaseObject , so it also has a Properties property that lists the properties of the WMI class, so all properties are listed:

 var wmiClass = new ManagementClass("Win32_ComputerSystem"); foreach (var prop in wmiClass.Properties) { Console.WriteLine(prop.Name); } 

(Each item in the Properties collection is an instance of PropertyData with lots of information about each property.)

+7
source

All Articles