File Exchange

image thumbnail

CPU Temperature

version (22.1 KB) by Sven Koerner
Get Data from MSAcpi_ThermalZoneTemperature using WMIService

1 Download

Updated 05 Aug 2011

View License

The function uses WMIService to get Information via WMI_MSAcpi_ThermalZoneTemperature-Class about the CPU.
It is an example on how to connect to COM and take use of Computer services.
Attention: BIOS must support temperature information.

Further Readings:

Programmed by Sven Koerner: koerner(underline)sven(add)
Date: 2011/08/05

Cite As

Sven Koerner (2020). CPU Temperature (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)


run matlab in non-administrator-mode cast error at colItems = objService.ExecQuery;
When changed to administrator-mode, problem solved.

Sven Koerner

Hi Vânia,
do you run matlab in administrator-mode?

Sorry, I forgot.
I'm using Windows 7 professional 64x and Matlab R2010a

Hi Sven, how are you?
thank you so much for your code.
I was trying to use it, but an error message appears:
>> info=getCPUTemperature
??? Invoke Error, Dispatch Exception:
Source: SWbemObjectSet
Description: Not supported

Error in ==> getCPUTemperature at 21
for i=1:1:colItems.Count

I installed WMI-CodeCreator and folloed the instructions you write to DAdler. As I pressed the button "Search for Proertie Values", the message "Results:Not supported" is given. Do you have any suggestions?


This does not work either. I tried this on different machines, too. Thank you anyway for you efforts.

Sven Koerner

Hello DAdler - my problem is, that I haven't the possebility to check the code on XP (in XP Mode of WIN 7 it doesn't produce results). However, when you get an answer from the WMICreator as you wrote, you can try the following:
1. set a breakpoint to line 21
2. go to matlab-prompt an run: >> t=colItems.get
3. then prompt >>t.Count --> is there a number or a message as answer?
4. If there is a number you can try to prompt >>colItems.Item(xy).get where xy is the number

Does it work?


Hello and thank you for your willingness to help. I can certainly run WMI-CodeCreator without problems and it does give me some results when I query the data from root\WMI. For example, both the VBS script I wrote above and WMI-CodeCreator give me the following results:

MSAcpi_ThermalZoneTemperature instance
ActiveTripPoint: 0,0,0,0,0,0,0,0,0,0
CriticalTripPoint: 3782
CurrentTemperature: 3352
InstanceName: ACPI\ThermalZone\TZ00_0
PassiveTripPoint: 3732
SamplingPeriod: 10

As I said, for XP machines your code does not work because of ItemIndex, but I am not sure how one can code it differently.

Sven Koerner

Hi DAdler, can you please download and run the WMI-CodeCreator:
In the tab "Query data from a WMI class" ypu select in the first listbox: root\WMI,
in the second listbox you select "MSAcpi_ThermalZoneTemperature" then in the third listbox you press shift und select all then you press the button "Search for Property Values" - does any value appear (?) or is there written the result is not supported?
Maybe you cam make a screenshot from WMICodeCreator with the query and the result?!


Hello again,

The error message I get when I run your code is the following:

??? No appropriate method, property, or field ItemIndex for class Interface.Microsoft_WMI_Scripting_V1.2_Library.ISWbemObjectSet.

which is true for Win XP! The method ItemIndex was added in Vista. This is the VBS script generated in WMI-CodeCreator

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM MSAcpi_ThermalZoneTemperature",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "MSAcpi_ThermalZoneTemperature instance"
Wscript.Echo "-----------------------------------"
If isNull(objItem.ActiveTripPoint) Then
Wscript.Echo "ActiveTripPoint: "
Wscript.Echo "ActiveTripPoint: " & Join(objItem.ActiveTripPoint, ",")
End If
Wscript.Echo "CriticalTripPoint: " & objItem.CriticalTripPoint
Wscript.Echo "CurrentTemperature: " & objItem.CurrentTemperature
Wscript.Echo "InstanceName: " & objItem.InstanceName
Wscript.Echo "PassiveTripPoint: " & objItem.PassiveTripPoint
Wscript.Echo "SamplingPeriod: " & objItem.SamplingPeriod


Sven Koerner

Hi DAdler - thank for rating.
I thougt that it will work under XP as well, however if if won't you can download the WMI-CodeCreator:
and than you can create the query for the XP-System. When the query works you can compare the VBScript from the wmicreator and the matlab code. In my opinion it is only necessary to get the query object with all data.
If you have trouble, maybe you can send me the error-message.



Very nice idea, indeed, but your code will only work for windows vista & 7 and not for XP! The reason is because the ItemIndex method is not present in XP. How can one code it for windows XP?


Sven Koerner

Haim, I guess maybe access is denied - do you start Matlab as an administrator? Can you download and run this as administrator:
With this tool you can query the WMIService.
There you can connect to root\wmi and go to namespace MSAcpi_ThermalZoneTemperature. There you can select some parameters and ask for it. Does this work?


WinXp 64-bit

Sven Koerner

@Haim: Hi, which OS do you use? When you have Windows>W2000 it should work...


Very nice idea, but when I try to run the file - I get the next error:
??? Invoke Error, Dispatch Exception:
Source: SWbemLocator
Description: Not found

Error in ==> getCPUTemperature at 16
objService = objLocator.ConnectServer('.', 'root\WMI'); % connet to WMI

Any idea?


MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux