locked
Reading CPU Temperature (WMI)

    Question

  • Hello everybody out there, i hope you can help Smile.

    I just searched a method to read my CPU Temperature, at first i tried W32_TemperatureProbe, but this didnt work.
    Now i use: MSAcpi_ThermalZoneTemperature

    I found this Code:

    Code Block

    strServer = "."

    Set objWMI = GetObject("winmgmts://" & strServer & "/root\WMI")
    Set objInstances = objWMI.InstancesOf("MSAcpi_ThermalZoneTemperature",48)

    On Error Resume Next
    For Each objInstance in objInstances
        With objInstance
            WScript.Echo .Active
            WScript.Echo Join(.ActiveTripPoint, ", ")
            WScript.Echo .ActiveTripPointCount
            WScript.Echo .CriticalTripPoint
            WScript.Echo .CurrentTemperature
            WScript.Echo .InstanceName
            WScript.Echo .PassiveTripPoint
            WScript.Echo .Reserved
            WScript.Echo .SamplingPeriod
            WScript.Echo .ThermalConstant1
            WScript.Echo .ThermalConstant2
            WScript.Echo .ThermalStamp
        End With
    On Error Goto 0
    Next



    I get the Integer:
    3026 for "Current Temperature"
    I use this Equation:  3026 / 10 - 273.15 to get the C Value...

    but the problem is that the displayed Temperature is wrong... i got the Tool "Notebook Hardware Monitor" and this application shows me: 42 C (i m sure this is right, because BIOS tells the same) but the WMI Code displays: 33 C...
    there are a difference of about 10 C... The Tool "SpeedFan" also shows 33 C... it realy weird..
    Any ideas ?

    Thank you in advantage and excuse me for my bad english..

    best wishes,
    tworule

    Sunday, September 30, 2007 2:48 AM

Answers

  • Hi Tworule,

     

    Firse welcome to MSDN Visual Basic Language Forum, this forum supports Visual Basic.NET (7, 7.1, 8, ...) issues only, so, your Visual Basic Script question is an off-topic here and this isn't the best place to ask it, here is a list of forums, newsgroups, resources and sites, to get an answer about your question :

    Second I recommend you read this thread about how to get a CPU temperature by VB.net code. We can find a CPU temperature reading in the root\WMI namespace, MSAcpi_ThermalZone Temperature class.  Current Temperature is the CPU temp in 0.1 degrees Kelvin.  We need to convert to Celsius by subtracting 2732 and dividing the result by 10. Also note that to measure the temperature of the CPU the users motherboard has to have a sensor. No sensor, no go. Here is the vb.net code snippet to get a CPU temperature.

    Code Block

    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 - 2732) / 10.0

                    MessageBox.Show(temp.ToString)

                Next

            Catch err As ManagementException

                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)

            End Try

        End Sub

    End Class

     

     

     

    Best regards,

    Riquel

    Thursday, October 04, 2007 2:47 AM

All replies

  • Hi Tworule,

     

    Firse welcome to MSDN Visual Basic Language Forum, this forum supports Visual Basic.NET (7, 7.1, 8, ...) issues only, so, your Visual Basic Script question is an off-topic here and this isn't the best place to ask it, here is a list of forums, newsgroups, resources and sites, to get an answer about your question :

    Second I recommend you read this thread about how to get a CPU temperature by VB.net code. We can find a CPU temperature reading in the root\WMI namespace, MSAcpi_ThermalZone Temperature class.  Current Temperature is the CPU temp in 0.1 degrees Kelvin.  We need to convert to Celsius by subtracting 2732 and dividing the result by 10. Also note that to measure the temperature of the CPU the users motherboard has to have a sensor. No sensor, no go. Here is the vb.net code snippet to get a CPU temperature.

    Code Block

    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 - 2732) / 10.0

                    MessageBox.Show(temp.ToString)

                Next

            Catch err As ManagementException

                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)

            End Try

        End Sub

    End Class

     

     

     

    Best regards,

    Riquel

    Thursday, October 04, 2007 2:47 AM
  •  It is impossible to only use VB to get CPU temperature. You must implement Monitor chip driver by C language. If mother-board manufacturers implement WMI in their drivers, you can get CPU temperature from WMI. So far as I know; no mother-board manufacturers implement WMI.
    First, you need know what monitor chip on your mother-board. You may look your mother-board. If you see LM75, LM78, Winbond ...etc trademark on your chip, download the datasheet of your chip according to your number of chip. The datasheet will show you how to access the chip.
     This web site contains some source code about CPU temperature. The author implemented monitor chip driver of W83697HF and W83627EHF which have Hardware Monitor function.
     http://temperature.myweb.hinet.net/index_en.htm The source code maybe help you.
    Friday, August 15, 2008 1:32 PM
  • Again, I see a reference to 'MSAcpi_ThermalZoneTemperature'.

    I have been unable to find out what that is supposed to be, but on at least my computer it is not the cpu temperature.
    It reports a consistent 40 degrees C, no matter what other programs report my actual cpu temperature to be.
    Sunday, August 23, 2009 10:52 AM
  • The Microsoft function for finding CPU temperature does not work.  Don't use it.  If you search the Microsoft forums, you will find the Microsoft people blaming the motherboard manufacturers for not implementing their standards.

    I don't think this excuses them for a bad API that gives us garbage data with no warning that the data is garbage.

     

     


    Monday, April 11, 2011 7:04 AM