ARTICLE

Get Property and Method Name of WMI Classes Programmatically in C#

Posted by Hiren Soni Articles | C# Language September 03, 2010
This article shows how you can get property name and method name programmatically instead of writing explicitly.
Reader Level:

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.

Login to add your contents and source code to this article
post comment
     

Thanks Hiren

Posted by Mike Gold Sep 03, 2010
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter