Results 1 to 9 of 9

Thread: WMI (Windows Management Instrumentation) - Get Hardware Info

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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:
    1. 'query for "Win32_Processor" class under WMI
    2.         Dim MyobjectQuery As New System.Management.ObjectQuery("select * from Win32_Processor")
    3.         'searcher is what runs the query, set the Query object as a parameter
    4.         Dim MySearcher As New System.Management.ManagementObjectSearcher(MyobjectQuery)
    5.         'calls the .Get method of the searcher, in order to get the object info
    6.         'This should loop for all processors if you have multiple ones
    7.         For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
    8.             'displays all properties for object in Mof format (there are other formats)
    9.             MessageBox.Show(Mgmt.GetText(Management.TextFormat.Mof))
    10.         Next
    11.         'this is an example of only displaying the particular properties you want
    12.         For Each Mgmt As System.Management.ManagementObject In MySearcher.Get()
    13.             MessageBox.Show(Mgmt("Manufacturer").ToString)
    14.             MessageBox.Show(Mgmt("Name").ToString)
    15.             MessageBox.Show(Mgmt("MaxClockSpeed").ToString)
    16.             MessageBox.Show(Mgmt("ProcessorID").ToString)
    17.             MessageBox.Show(Mgmt("ProcessorType").ToString)
    18.             MessageBox.Show(Mgmt("Revision").ToString)
    19.         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
  •  



Click Here to Expand Forum to Full Width