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.

Figure1:

image.JPG

Code and explanation:

            // Schema query for getting infomation for Win32_LogicalDisk class
            ManagementObjectSearcher q = new ManagementObjectSearcher(@"SELECT * FROM meta_class WHERE __this ISA ""Win32_LogicalDisk""");

            // get the each class from the select query.
            foreach (ManagementClass c in q.Get())
            {
                // get the each propery name of WMI class
                foreach (PropertyData d in c.Properties)
                {
                    listBox1.Items.Add(d.Name);
                }

                // get the each method name of WMI class
                foreach (MethodData m in c.Methods)
                {

                    listBox2.Items.Add(m.Name);

                }
            }



Hope you understand it,

Thanks.

Up Next
    Ebook Download
    View all
    Learn
    View all