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.
Programmed by Sven Koerner: koerner(underline)sven(add)gmx.de
Sven Koerner (2020). CPU Temperature (https://www.mathworks.com/matlabcentral/fileexchange/32440-cpu-temperature), MATLAB Central File Exchange. Retrieved .
run matlab in non-administrator-mode cast error at colItems = objService.ExecQuery;
When changed to administrator-mode, problem solved.
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:
??? Invoke Error, Dispatch Exception:
Description: Not supported
Error in ==> getCPUTemperature at 21
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.
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:
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.
Hi DAdler, can you please download and run the WMI-CodeCreator: http://www.microsoft.com/download/en/details.aspx?id=8572.
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?!
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 "MSAcpi_ThermalZoneTemperature instance"
If isNull(objItem.ActiveTripPoint) Then
Wscript.Echo "ActiveTripPoint: "
Wscript.Echo "ActiveTripPoint: " & Join(objItem.ActiveTripPoint, ",")
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
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?
Haim, I guess maybe access is denied - do you start Matlab as an administrator? Can you download and run this as administrator: http://www.microsoft.com/download/en/details.aspx?id=8572
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?
@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:
Description: Not found
Error in ==> getCPUTemperature at 16
objService = objLocator.ConnectServer('.', 'root\WMI'); % connet to WMI