Get Property And Method Name Of WMI Classes Programmatically In C#


This article shows how you can get property name and method name programmatically instead of writing explicitly.

There is one special class called "meta_class" which provides schema information.

It identifies select query as schema query.

Query look like this

SELECT * FROM meta_class WHERE __this ISA "Win32_LogicalDisk"

Here, WMI class name declare in double quote in select query.


Code and explanation

// Schema query for getting information for Win32_LogicalDisk class
ManagementObjectSearcher query = new ManagementObjectSearcher(@"SELECT * FROM meta_class WHERE __this ISA ""Win32_LogicalDisk""");
// Get each class from the select query.
foreach (ManagementClass managementClass in query.Get())
    // Get each property name of WMI class.
    foreach (PropertyData property in managementClass.Properties)
    // Get each method name of WMI class.
    foreach (MethodData method in managementClass.Methods)

I hope you understand it.


Similar Articles