locked
Getting CPU temp RRS feed

  • Question

  • Does anyone have the code for getting the cpu temps for a program?
    Saturday, November 12, 2005 6:18 AM

Answers

  • not all machines can support reading of the cpu temperature, it's a function of your BIOS software. Sometimes the bios manufacturer will supply dll's that you can reference to call the required function and return the details, when you reboot your computer get the bios manufacturer and model number and check and see if they support it.

    Cathal
    Sunday, November 13, 2005 4:13 AM
    Moderator

All replies

  • not all machines can support reading of the cpu temperature, it's a function of your BIOS software. Sometimes the bios manufacturer will supply dll's that you can reference to call the required function and return the details, when you reboot your computer get the bios manufacturer and model number and check and see if they support it.

    Cathal
    Sunday, November 13, 2005 4:13 AM
    Moderator
  • Using WMI may be the "cleanest" way of doing it, by reading the Win32_TemperatureProbe property:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_temperatureprobe.asp

    This would need the OEM to have a driver for it, which I unfortunately think is more of the exception than the rule.

    There's also this article abou this that doesn't sound good as for using the WMI:
    http://support.microsoft.com/default.aspx?scid=kb;en-us;306852

    It's unfortunate, as reading WMI data is supported by .NET classes in the Management namespace. See also here for that if you're still interested in digging here further: http://www.devcity.net/PrintArticle.aspx?ArticleID=144

    If you wouldn't use WMI, I guess the alternative would be to work more low-level with SMBIOS data, possibly using undocumented methods that are incompatible from hardware to hardware. There are e.g. the tool Motherboard Monitor that comes with drivers IIRC to support various hardware, which shows there may unfortunately be no widely supported generic high-level API for this.
    Monday, November 14, 2005 10:45 PM
  • I'm not sure how manufacturer sensitive this is or that accessing bioses require a special dll.


    http://mbm.livewiredev.com/


    This url has the most wonderful free motherbord monitor. The thing is, is that it's pretty universal with an extreme diversity of motherboards that it will function with.

    The developer of this appears to just absolutely love hardware. I best if you wrote to him he'd tell you how it's done. I have a guess, just a guess if he responds with code, you will be looking at some fairely esoteric C.

    This developer, im sure supplies a generic driver and tables of information about different mother boards.

    Renee
    Monday, November 14, 2005 11:31 PM
  • see this site....

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=204154&SiteID=1
    Monday, April 17, 2006 4:55 PM
  • Hi there

     

    This works for me: (using System.Management, & System.Windows.Forms for the MessageBox)

     

    ManagementClass processClass = new ManagementClass(@"root\WMI:MSAcpi_ThermalZoneTemperature");

    foreach (ManagementObject service in processClass.GetInstances())

    {

    MessageBox.Show("CPU Temperature: " + service.GetPropertyValue("CurrentTemperature"));

    }

     

    I found that with all of these posts, some aspects of the replies are right, but in some they fall short.

    When you combine the expertise, you come out at something workable.

    If you're trying to do the Win32_TemperatureProbe through WMI and you're getting nothing back, it is most likely that your motherboard doesn't have the appropriate driver, needed to expose the value.

    If you check in Device Manager under System Devices, you should see ACPI Thermal Zone. If it's there, then the code above should return the current cpu temperature.

     

    If your motherboard drivers exposed the necessary info, then this code from other forums probably would work for you:

     

    SelectQuery myQuery = new SelectQuery("SELECT CurrentReading from Win32_TemperatureProbe");

    ManagementObjectSearcher mySearcher = new ManagementObjectSearcher(myQuery);

     

    foreach (ManagementBaseObject obj in mySearcher.Get())

    {

    MessageBox.Show("Temp: " + obj["CurrentReading"]);

    }

     

    Unfortunately it returns nothing on my box, and I don't have the resources here to test it on others.

    But my feeling is that MSAcpi_ThermalZoneTemperature will work for you.

     

    And btw, the output is in 10ths of Kelvin, so to convert, you can use this method...

    static decimal ConvertToCelsius(string reading)

    {

    return (decimal.Parse(reading) / 10 - 273.15m);

    }

     

    L8r

    M

    Tuesday, December 18, 2007 9:34 AM
  •  

    none of this script works... the first give me always 52° and the second return empty string!! any ideas?? please i need this!
    Tuesday, February 12, 2008 12:46 AM
  • I found this VbScript works well.

     

    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 "Current CPU Temperature: " & (.CurrentTemperature - 2732)/10 & "°C" 
            WScript.Echo "Temperature Sampling Period: " & .SamplingPeriod & " seconds" 
            WScript.Echo "Active Trip Point Count: " & .ActiveTripPointCount      
        End With 
    On Error Goto 0  
    Next 

    Regards,
    Richard
    Richard J. Rothery Jr.
    • Edited by rjstinyc Thursday, June 12, 2008 10:21 PM Formatting
    Thursday, June 12, 2008 10:18 PM
  •  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 2:09 PM