smaguire
asked on
How to Read CPU Temperature from C#?
hi,
Does anyone know how to read a CPU Temperature from a custom application? I can see the CPU Temperature and Fan Speed from the bios when i boot my computer, I know the computer is using a special chip to display that info "Winbond W83627THG". I know it can be done, I downloaded this software "Speed Fan" from this link:
http://www.almico.com/forumindex.php which works great but i want the CODE on how to display those info into my application
thanks
Does anyone know how to read a CPU Temperature from a custom application? I can see the CPU Temperature and Fan Speed from the bios when i boot my computer, I know the computer is using a special chip to display that info "Winbond W83627THG". I know it can be done, I downloaded this software "Speed Fan" from this link:
http://www.almico.com/forumindex.php which works great but i want the CODE on how to display those info into my application
thanks
ASKER
Thanks gregoryyoung for your reply,
I am not really experienced with WMI. Do I have to create a WMI application and try to query?
I will try to re-read the article again, everything seems to be done in scripts and C nothing in C#
I am not really experienced with WMI. Do I have to create a WMI application and try to query?
I will try to re-read the article again, everything seems to be done in scripts and C nothing in C#
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this:
- add reference to System.Management.dll
- add using System.Management;
- add reference to System.Management.dll
- add using System.Management;
ManagementClass processClass = new ManagementClass(@"root\cimv2:Win32_TemperatureProbe");
foreach(ManagementObject service in processClass.GetInstances()) {
Console.WriteLine("Service = " + service.GetPropertyValue("CurrentReading.Description"));
}
ASKER
wackym: I added your code to a button click command but it doesn't return anything:
it doesn't go into the foreach loop, it exists rightaway
any idea?
thanks,
it doesn't go into the foreach loop, it exists rightaway
any idea?
thanks,
private void button1_Click(object sender, EventArgs e)
{
ManagementClass processClass = new ManagementClass(@"root\cimv2:Win32_TemperatureProbe");
foreach (ManagementObject service in processClass.GetInstances())
{
Console.WriteLine("Service = " + service.GetPropertyValue("CurrentReading.Description"));
}
}
its not as simple as that usually as the hardware vendors have not exactly standardized this ... some do it in different ways (actually some commentary on this in the link I sent see comment from xtmouse) as such you will probably have to poke around a bit ... its probably there but its probably manufacturer specific.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
wackym, I downloaded the software and its showing me alot of objects but can't for some reason call one of them, for example, i modified the code you posted like the following so i can see all instances of Win32_ComputerSystem, but its giving me an error Bot Found!
private void button1_Click(object sender, EventArgs e)
{
ManagementClass processClass = new ManagementClass(@"root\cim v2:Win32_C omputerSys tem");
foreach (ManagementObject service in processClass.GetInstances( ))
{
Console.WriteLine("Service = " + service.GetPropertyValue(" CurrentRea ding.Descr iption"));
}
}
now it goes into the loop but it throws an error not found. any idea why?
thanks again
private void button1_Click(object sender, EventArgs e)
{
ManagementClass processClass = new ManagementClass(@"root\cim
foreach (ManagementObject service in processClass.GetInstances(
{
Console.WriteLine("Service
}
}
now it goes into the loop but it throws an error not found. any idea why?
thanks again
Hmm, you're requesting to read a non-existing property CurrentReading.Description from Win32_ComputerSystem...you 'll have to find the right property with info about CPU temperature.
ASKER
Thanks wackym, I got some variables to show their values just fine. Just one question though:
Does looking up WMI parameters/variables slow down your computer? because my computer has slowed down big time, and i am thinking if i should have a timer to check the status of my CPU Temperature or not if its this slow?
thanks
Does looking up WMI parameters/variables slow down your computer? because my computer has slowed down big time, and i am thinking if i should have a timer to check the status of my CPU Temperature or not if its this slow?
thanks
It shouldn't be significantly slower ... I have code that reads <> 50 WMI values a second without any real performance cost ... I wouldn't imagine that you would want to check temperature more than every few seconds though unless you are planning to flash freeze etc the machine in testing ... its extremely rare that you change more than a 1/5 of a degree within even say a 15 or 30 second period. Even with that though I would imagine that even once every 5 seconds would give you reasonable results ...
ASKER
Thank you guys
If its in WMI its a pretty easy task to read the value.