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.
Open up a Visual Basic Windows Form project and call it anything you'd like.
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.
Double-click the button you just created to take yourself to its click event function in code view.
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")
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
- 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.