the idea of what i want to do is to display the cpu temperature in a label that will refresh through a timer. i have search several sites including this one that do have the code and how to do it, but then my problem is that several items are not declared and have no clue how to declare them?

most of the code being something similar to this
but then the things that are not declared are
*ManagementObjectSearcher
*ManagementObject
*ManagementException

Try
            Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")
            For Each queryObj As ManagementObject In searcher.Get()
                Dim temp As Double = CDbl(queryObj("CurrentTemperature"))
                temp = (temp - 2732) / 10.0
                MessageBox.Show(temp.ToString)
            Next
        Catch ex As ManagementException
            MessageBox.Show(ex.Message)
        End Try

I honestly have no idea what to do with this anyway!

Im assuming it is completely possible to get the temp somehow, maybe not in vb but maybe something else, because i am currently running "Core Temp"

hopefully this makes since to someone other than me!
if you can i'd appreciate the help!

But, how do i actually get it to show?

Show what? the temperature result?

All I did is copy/paste your code, add the reference as I mention to you, and run the form, and it give me "not supported"

So I guess the code is working some some hardware.

Did you manage to run the code?

  1. Make a new form
  2. Add reference to the system.management that is:
    a) right click on your project solution file
    b) go to add reference, you will be taken to a window where first tab is com component
    c) scroll down to system.management
    d) press OK
  3. Add a label from the toolbox
  4. Add a button from the toolbox

copy paste the following code:

Imports System
Imports System.Management

Public Class frmMain

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")

            For Each queryObj As ManagementObject In searcher.Get()
                Dim temp As Double = CDbl(queryObj("CurrentTemperature"))
                temp = (temp - 2732) / 10.0
                MessageBox.Show(temp.ToString)
            Next

        Catch ex As ManagementException
            MessageBox.Show(ex.Message)
        End Try

    End Sub

End Class

NOTE: this code will only run if your running windows XP or maybe vista & you need to have administrative rights on the machine.

Regards.

Ok, so here's what i have now

Imports System
Imports System.Management

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")
            For Each queryObj As ManagementObject In searcher.Get()
                Dim temp As Double = CDbl(queryObj("CurrentTemperature"))
                temp = (((temp / 10) - 273.15) * 1.8) + 32

                MessageBox.Show(temp.ToString)
            Next
        Catch ex As ManagementException
            MessageBox.Show(ex.Message)
        End Try


    End Sub
End Class

I've tweaked it to show in Fahrenheit
But, it only shows 2 values
and every time the button is clicked it only shows those same 2 values
is there something being done wrong or is this just how it is?

oh and i tried sending it to a label by putting

label1.text "" & temp.ToString & ""

instead of

MessageBox.Show(temp.ToString)

but the label only showed one value instead of the 2
and it was always the same
is there any way i could get the 'current' value(s) and display them separately?
preferably in a label or 2

Edited 7 Years Ago by Smalls: change in spacing - OCD

Ok, so here's what i have now

Imports System
Imports System.Management

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim searcher As New ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")
            For Each queryObj As ManagementObject In searcher.Get()
                Dim temp As Double = CDbl(queryObj("CurrentTemperature"))
                temp = (((temp / 10) - 273.15) * 1.8) + 32

                MessageBox.Show(temp.ToString)
            Next
        Catch ex As ManagementException
            MessageBox.Show(ex.Message)
        End Try


    End Sub
End Class

I've tweaked it to show in Fahrenheit
But, it only shows 2 values
and every time the button is clicked it only shows those same 2 values
is there something being done wrong or is this just how it is?

oh and i tried sending it to a label by putting

label1.text "" & temp.ToString & ""

instead of

MessageBox.Show(temp.ToString)

but the label only showed one value instead of the 2
and it was always the same
is there any way i could get the 'current' value(s) and display them separately?
preferably in a label or 2

Thanks for using my code :)

you should put a timer & put the code block in a function make that timer call the function every one second & your values will get refreshed every 1 second.

yes you can get the values into 2 different labels you can use substring functions, so u take a part of the function to the first label & another to the second label.

if you need help coding that, you just ask!

regards.

I'm not real sure on how to do that could you show me?

also, from what i've seen, the values are always the same.
shouldn't it be that every time you click the button , the app goes and gets fresh values?

Edited 7 Years Ago by Smalls: typo

I'm not to sure on how to get them into 2 labels using sub-strings?

but also, from what i see the values are not getting refreshed, the only 2 values I'm getting are 134.69 and 123.89

and why would there be that big of a difference, Core Temp never shows that big of difference, nor are the values the same as core temp?

I'm just sort of curious, what are these numbers from and why are they so different?

This article has been dead for over six months. Start a new discussion instead.