Click here to Skip to main content
11,412,526 members (75,435 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
I am trying to retrieve a computer's CPU temp. I have posted my code below. Can someone please tell me where my problem is?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
namespace SServer.Common.Diagnostics.SystemInfo
    public class Temperature
        public double CurrentValue { get; set; }
        public string InstanceName { get; set; }
        public static List<string> Temperatures
                List<string> result = new List<string>();
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"root\CIMV2", "SELECT * FROM Win32_TemperatureProbe");
                foreach (ManagementObject obj in searcher.Get())
                    if (obj != null)
                        Double temp = Convert.ToDouble(obj["CurrentTemperature"].ToString());
                        temp = (temp - 2732) / 10.0;
                        result.Add(new Temperature
                            CurrentValue = temp,
                            InstanceName = obj["CurrentTemperature"].ToString()
                return result;
Posted 10-Oct-12 6:10am
Wes Aday at 10-Oct-12 11:16am
What problem?
Christopher Smit at 10-Oct-12 11:24am
Double temp = Convert.ToDouble(obj["CurrentTemperature"].ToString());

This line shows the following Execption.

ManagementException was unhandled - Not Found
Richard MacCutchan at 10-Oct-12 12:00pm
Looks like obj["CurrentTemperature"] does not exist.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

CurrentTemperature does not exist - it is CurrentReading.

But I have more bad news for you: that probably won't work either.
See MSDN: Win32_TemperatureProbe class[^]

"Most of the information that the Win32_TemperatureProbe WMI class provides comes from SMBIOS. Real-time readings for the CurrentReading property cannot be extracted from SMBIOS tables. For this reason, current implementations of WMI do not populate the CurrentReading property. The CurrentReading property's presence is reserved for future use."
Christopher Smit at 10-Oct-12 15:11pm
Is there really NO WAY to do this? I mean there must be something... Right?
OriginalGriff at 10-Oct-12 15:25pm
As far as I know, no, there is no generic way to get this. The problem is that WMI (et al) rely on motherboard manufacturers providing that info via their drivers - and most don't bother.
Have a google, and you will see what I mean.
Sorry to be the bearer of bad news, but...
Christopher Smit at 10-Oct-12 15:27pm
Well that sucks.. Would have been pretty epic being able to do that.. Thanks anyway :)
Christopher Smit at 15-Oct-12 14:59pm
I've done a little research.. How do programs like CPUID get the Temperature for the CPU?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 414
1 Sascha Lefévre 200
2 Maciej Los 155
3 ProgramFOX 130
4 Sergey Alexandrovich Kryukov 110
0 Sergey Alexandrovich Kryukov 9,025
1 OriginalGriff 7,247
2 Maciej Los 3,525
3 Abhinav S 3,248
4 Peter Leow 3,059

Advertise | Privacy | Mobile
Web04 | 2.8.150427.1 | Last Updated 10 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100