4.33333

4.3 | 3 ratings Rate this file 13 Downloads (last 30 days) File Size: 22.13 KB File ID: #32440
image thumbnail

CPU Temperature

by Sven Körner

 

05 Aug 2011

Get Data from MSAcpi_ThermalZoneTemperature using WMIService

| Watch this File

File Information
Description

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:
  http://msdn.microsoft.com/de-de/library/ms811533.aspx
  http://msdn.microsoft.com/en-us/library/aa394579(v=vs.85).aspx
  http://www.scriptinternals.de/new/defaultUS.asp?WMI_MSAcpi_ThermalZoneTemperature
  http://www.microsoft.com/download/en/details.aspx?id=8572

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

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (15)
09 Aug 2011 Haim  
09 Aug 2011 Haim

Hi.
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?

09 Aug 2011 Sven Körner

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

10 Aug 2011 Haim

WinXp 64-bit

11 Aug 2011 Sven Körner

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?

19 Oct 2011 DAdler

Hello,

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?

Thanks

23 Oct 2011 Sven Körner

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:
http://www.microsoft.com/download/en/details.aspx?id=8572
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.

23 Oct 2011 DAdler

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: "
    Else
        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
Next

Thanks

24 Oct 2011 Sven Körner

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?!

24 Oct 2011 DAdler

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.

24 Oct 2011 Sven Körner

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?

29 Oct 2011 DAdler

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

31 Jan 2012 Vânia Silvério

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?
Thanks

31 Jan 2012 Vânia Silvério

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

07 Feb 2012 Sven Körner

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

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
com Sven Körner 05 Aug 2011 15:44:02
api Sven Körner 05 Aug 2011 15:44:02
cpu Sven Körner 05 Aug 2011 15:44:02
sysinternals Sven Körner 05 Aug 2011 15:44:02
temperature Sven Körner 05 Aug 2011 15:44:02
data Sven Körner 05 Aug 2011 15:44:02

Contact us at files@mathworks.com