|
-
Feb 15th, 2006, 06:12 PM
#1
WMI (Windows Management Instrumentation) - Get Hardware Info
This is an example of how easy it is to get various hardware information using WMI. The process includes declaring an object query, using a WMI class name that you want to retrieve info for, then executing the query to return the object information and properties. The ManagementObjectSearcher object has a simple .Get method that is used in order to retrieve the information for the particular WMI class.
You can retrieve WMI information in .NET by using methods and objects in the System.Management namespace. In order to try out the example code below, remember to add a reference to System.Management in your project.
Below is a simple example of getting processor information on the computer. Notice the "Win32_Processor" class. This is only one of several classes you can retrieve information for. There is an example to show all properties for the object, as well as an example of only getting the particular properties you wish.
VB Code:
'query for "Win32_Processor" class under WMI
Dim MyobjectQuery As New System.Management.ObjectQuery("select * from Win32_Processor")
'searcher is what runs the query, set the Query object as a parameter
Dim MySearcher As New System.Management.ManagementObjectSearcher(MyobjectQuery)
'calls the .Get method of the searcher, in order to get the object info
'This should loop for all processors if you have multiple ones
For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
'displays all properties for object in Mof format (there are other formats)
MessageBox.Show(Mgmt.GetText(Management.TextFormat.Mof))
Next
'this is an example of only displaying the particular properties you want
For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
MessageBox.Show(Mgmt("Manufacturer").ToString)
MessageBox.Show(Mgmt("Name").ToString)
MessageBox.Show(Mgmt("MaxClockSpeed").ToString)
MessageBox.Show(Mgmt("ProcessorID").ToString)
MessageBox.Show(Mgmt("ProcessorType").ToString)
MessageBox.Show(Mgmt("Revision").ToString)
Next
To learn more about the TONS of classes and objects you can retrieve info for (as well as to find documentation of the different object properties), visit this link: http://msdn.microsoft.com/library/de...mi_classes.asp
Last edited by gigemboy; Feb 16th, 2006 at 04:22 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|