locked
Reading CPU temperature RRS feed

  • Question

  • Hello,

    i'd like to read the cpu temperature in a VB application.
    i tried to get it using WMI but that isn't supported by my computer.

    i used code i found on this forum and what i get from the WMI code creator.

    this is the code created with the WMI code creator.

    Code Block

    Imports System
    Imports System.Management
    Imports System.Windows.Forms

    Namespace WMISample

        Public Class MyWMIQuery

            Public Overloads Shared Function Main() As Integer

                Try
                    Dim searcher As New ManagementObjectSearcher( _
                        "root\WMI", _
                        "SELECT * FROM MSAcpi_ThermalZoneTemperature")

                    For Each queryObj As ManagementObject in searcher.Get()

                        Console.WriteLine("-----------------------------------")
                        Console.WriteLine("MSAcpi_ThermalZoneTemperature instance")
                        Console.WriteLine("-----------------------------------")
                        Console.WriteLine("CurrentTemperature: {0}", queryObj("CurrentTemperature"))
                    Next
                Catch err As ManagementException
                    MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
                End Try
            End Function
        End Class
    End Namespace


    any help is welcome

    Greetings El Mariachi
    Saturday, November 3, 2007 11:50 PM

Answers

  • check that you have Windows Script Host installed

    and from the command line  try this script

     

    Code Block

    strComputer = "."
    Set objWMIService = GetObject( _
        "winmgmts:\\" & strComputer & "\root\WMI")
    Set searcher = objWMIService.ExecQuery ("SELECT * FROM MSAcpi_ThermalZoneTemperature")
    For Each queryObj in searcher
           wscript.echo "-----------------------------------"
           wscript.echo "MSAcpi_ThermalZoneTemperature instance"
           wscript.echo "-----------------------------------"
           wscript.echo queryObj.CurrentTemperature
    Next

     

     

    if you still see nothing maybe you have some error in command SELECT or your computer has not any sensor, because if you see nothing, meens that objWMIService.ExecQuery returns empty query.
    Sunday, November 4, 2007 9:55 PM

All replies

  • try this:

     

         

    Code Block

        Public Overloads Shared Function Main() As Integer
          Try

       const strComputer as string="."

       Dim objWMIService=GetObject("winmgmts:\\" &   strComputer & "\root\WMI")

       Dim objItems=objWMIService.ExecQuery("SELECT * FROM _

                    MSAcpi_ThermalZoneTemperature")

       Dim Obj as object

       For Each Obj in objItems
        Console.WriteLine("-----------------------------------")

        Console.WriteLine("MSAcpi_ThermalZoneTemperature instance")
        Console.WriteLine("-----------------------------------")
        Console.WriteLine("CurrentTemperature: {0}", Obj.CurrentTemperature)
       Next

     Catch err As ManagementException
       MessageBox.Show("An error occurred while querying for WMI data: "_

                        & err.Message)
     End Try

    End Function

     

     

     

    Sunday, November 4, 2007 4:38 PM
  • try this:

     

         

    Code Block

        Public Overloads Shared Function Main() As Integer
          Try

       const strComputer as string="."

       Dim objWMIService=GetObject("winmgmts:\\" &   strComputer & "\root\WMI")

       Dim objItems=objWMIService.ExecQuery("SELECT * FROM _

                    MSAcpi_ThermalZoneTemperature")

       Dim Obj as object

       For Each Obj in objItems
        Console.WriteLine("-----------------------------------")

        Console.WriteLine("MSAcpi_ThermalZoneTemperature instance")
        Console.WriteLine("-----------------------------------")
        Console.WriteLine("CurrentTemperature: {0}", Obj.CurrentTemperature)
       Next

     Catch err As Exception
       MessageBox.Show("An error occurred while querying for WMI data: "_

                        & err.Message)
     End Try

    End Function

     

     

     

    Sunday, November 4, 2007 4:39 PM
  • It didn't work
    i didn't get any data back
    just a blank screen...
    not even the error message
    Sunday, November 4, 2007 5:34 PM
  • check that you have Windows Script Host installed

    and from the command line  try this script

     

    Code Block

    strComputer = "."
    Set objWMIService = GetObject( _
        "winmgmts:\\" & strComputer & "\root\WMI")
    Set searcher = objWMIService.ExecQuery ("SELECT * FROM MSAcpi_ThermalZoneTemperature")
    For Each queryObj in searcher
           wscript.echo "-----------------------------------"
           wscript.echo "MSAcpi_ThermalZoneTemperature instance"
           wscript.echo "-----------------------------------"
           wscript.echo queryObj.CurrentTemperature
    Next

     

     

    if you still see nothing maybe you have some error in command SELECT or your computer has not any sensor, because if you see nothing, meens that objWMIService.ExecQuery returns empty query.
    Sunday, November 4, 2007 9:55 PM
  • Hi El Mariachi,

     

    We can find a CPU temperature reading in the root\WMI namespace, MSAcpi_ThermalZone Temperature class. Also note that to measure the temperature of the CPU the user's motherboard has to have a sensor. If the motherboard hasn't this sensor, you can't get a CPU temperature. You use the wmi code creator to execute the above code snippet. The tool puts the code snippet into the try/catch block. This will generate the error.  

     

    Best regards,

    Riquel

    Wednesday, November 7, 2007 9:37 AM
    Moderator
  • hi,
           i was try this coding,but i have critical error

     Error :   
     Exception from HRESULT: 0x80041017 
         


    visa
    Saturday, July 26, 2008 9:48 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:27 PM
  • Thanks friend,
                   
                    I didn't  have chip on the mother board


    John
    Friday, September 26, 2008 7:49 AM
  • I've seen several answers that refer to 'MSAcpi_ThermalZoneTemperature'.  I was unable to find out what that temperature is supposed to be, but at least on my
    computer that does NOT seem to be 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:51 AM