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

Introduction

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.

image.JPG

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)
    {
        listBox1.Items.Add(property.Name);
    }
    // Get each method name of WMI class.
    foreach (MethodData method in managementClass.Methods)
    {
        listBox2.Items.Add(method.Name);
    }
}

I hope you understand it.

Thanks.


Similar Articles