WMI Programming with Visual Basic.NET: Tips and Tricks - Retrieving all properties of a WMI class without knowing their names
(Page 2 of 5 )
In all of my previous parts of this series, I specified the properties I wanted to display manually. In order to do that, we should check with the WMI SDK documentation to get the full list of properties (and of course descriptions) of a particular WMI class. Now, is there any way to display all the properties at one time?
The answer is yes. We do have a way to display all the properties (along with values) of almost any WMI class dynamically. Before we implement it practically, I need to introduce two of the new classes of the “System.Management” namespace:
- PropertyDataCollection
- PropertyData
Using the “Properties” property of the “ManagementObject” class, we transfer all properties (along with values) to an object reference of type “PropertyDataCollection”. We extract each and every property of information from “PropertyDataCollection” by using “PropertyData”. The following program illustrates the same.
DimdtAsNewDataTable
dt.Columns.Add("Name")
dt.Columns.Add("Value")
DimdiskAsNewManagementObject("Win32_LogicalDisk.deviceid='c:'")
DimdiskPropertiesAsPropertyDataCollection = disk.Properties
DimdiskPropertyAsPropertyData
ForEachdiskPropertyIndiskProperties
DimdrAsDataRow = dt.NewRow
dr("Name") = diskProperty.Name
dr("Value") = diskProperty.Value
dt.Rows.Add(dr)
NextdiskProperty
dt.AcceptChanges()
Me.DataGrid1.DataSource = dt
The above program gets all of the properties along with their values into a data table, and finally gets them displayed through a data grid. The next section gives you a detailed explanation of the above program.
Next: How does the program work? >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee