zxhou1 发表于 2014-5-26 15:23:32

用WMI不能获取CPU的温度,求解决

用WMI可以获取硬盘温度,但是显示CPU温度为空,我用的是Win 7系统,Autoit版本3.3.7。有大神指点下这是为什么,怎么解决啊。。。
MsgBox(0,'',_ACPI_Temp())
MsgBox(0,'',_WMI_DriveTemperature())
Func _ACPI_Temp() ;CPU Temp
    Local $wbemFlagReturnImmediately = 0x10, $strComputer, $objWMIService, $colItems, $CurrTemp
    Local $wbemFlagForwardOnly = 0x20
    $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM MSAcpi_ThermalZoneTemperature", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    For $objItem In $colItems
         $CurrTemp = ($objItem.CurrentTemperature - 2732) / 10
       Next
   Return $CurrTemp
EndFunc
Func _WMI_DriveTemperature() ; Hard Drive temp
   Local $wbemFlagReturnImmediately = 0x10, $objWMIService, $colItems, $colTemp , $strComputer, $objItem, $s
   Local $wbemFlagForwardOnly = 0x20
   Local $strVendorSpecific
   $strComputer = "."
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\wmi")
        $colTemp = $objWMIService.ExecQuery('SELECT * FROM MSStorageDriver_ATAPISmartData', "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
        For $objItem In $colTemp
                   $strVendorSpecific = $objItem.VendorSpecific
           For $i = 2 To UBound($strVendorSpecific) - 1 Step 12
            If $strVendorSpecific[$i] = 0xC2 Then ; find Vendor Parameter #194 - Temperatur
                $s &= " " & $strVendorSpecific[$i + 5] ; Raw/Value celsuis
                ContinueLoop 2
            EndIf
      Next
      For $i = 2 To UBound($strVendorSpecific) - 1 Step 12
            If $strVendorSpecific[$i] = 0xBE Then ; find Vendor Parameter #190 - Airflow Temperatur (if no tempetature is found)
                $s &= " " & $strVendorSpecific[$i + 5] ; Raw/Value celsuis
                ContinueLoop 2
            EndIf
       Next
                If $s = 0 or $s = "N/A" or $s = "" or $s = @error then
          $s = $strVendorSpecific
          Endif
                  
          Next
Return $s
EndFunc

lixiaolong 发表于 2014-5-26 20:10:43

回复 1# zxhou1

加 #RequireAdmin 试试

joyran 发表于 2014-5-26 21:51:33

{:face (327):}呵呵!顶

zxhou1 发表于 2014-5-27 08:55:02

回复 2# lixiaolong
不行啊,我在xp系统运行都没问题的,win7就不行了

zxhou1 发表于 2014-5-29 13:40:58

求解决啊,大神

zxw91 发表于 2024-10-28 21:39:05

学习一下如何操作

zxw91 发表于 2024-10-28 22:09:37

谢分享,学习下
页: [1]
查看完整版本: 用WMI不能获取CPU的温度,求解决