How to Access the CPU Temperature in VB

Written by mikhail polenin Google
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Access the CPU Temperature in VB
Keeping an eye on your CPU temperature might give you a clue of how well your cooling system is working for you. (cpu 1 image by Robert Molnar from

If you are building a simple hardware statistics program, the first place to look in is the Windows Management Instrumentation (WMI) reference, where you will find a lot of neat queries you can make to the interface to find out many things about your system. You can find the temperature of your CPUs by sending a query to the WMI for "MSAcpi_ThermalZoneTemperature" and seeking to the "CurrentTemperature" value. This is easier said than done, though, so make sure to touch up on your programming skills.

Skill level:


  1. 1

    Open up a Visual Basic Windows Form project and call it anything you'd like.

  2. 2

    Create a button by selecting the button item on your toolbox and dragging a box across your form covering the area you would like the button to appear in.

  3. 3

    Double-click the button you just created to take yourself to its click event function in code view.

  4. 4

    Declare a new Management Object Searcher inside the click event and pass its construction parameters as the root WMI class with a query for "MSAcpi_ThermalZoneTemperature." You can do it like this:

    Dim s As New System.Management.ManagementObjectSearcher( _ "root/WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")

  5. 5

    Iterate through the searcher you created and make a temporary value within the iteration to display the value. The temperature of the CPU is going to be displayed in a number of 0.1 units of Kelvin. For example, if the CPU temperature is 27455, this can be interpreted as 2745.5 degrees Kelvin. You will have to convert the temperature to the unit you want to display. The following example does the iteration and displays the CPU temperature in Celsius:

    For Each q As ManagementObject In s.Get() Dim tmp As Double = CDbl(q("CurrentTemperature") tmp = (tmp -- 2732) / 10.0 MessageBox.Show(tmp.ToString) Next

Tips and warnings

  • Do not forget to convert the temperature to a string since it is a "double" value, and such values cannot be shown in the context of a message box.
  • The following formula will convert the value to Fahrenheit, in case you do not want the temperature in Celsius: tmp = ((tmp -- 2732) / 10.0) * (9 / 5) + 32
  • If you find the instructions to be rather confusing, you probably do not understand the basic concepts of Visual Basic. Check out the resources section for a tutorial that will get you on your way.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.