在我的电脑上,我正在尝试获取CPU温度。在StackOverflow上搜索,我找到了这个:
C:\WINDOWS\system32>wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature
但是我收到了这个错误:
Node - ADMIN
ERROR:
Description = Not supported
在我的电脑上,我正在尝试获取CPU温度。在StackOverflow上搜索,我找到了这个:
C:\WINDOWS\system32>wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature
但是我收到了这个错误:
Node - ADMIN
ERROR:
Description = Not supported
function Get-Temperature {
$t = Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
$returntemp = @()
foreach ($temp in $t.CurrentTemperature)
{
$currentTempKelvin = $temp / 10
$currentTempCelsius = $currentTempKelvin - 273.15
$currentTempFahrenheit = (9/5) * $currentTempCelsius + 32
$returntemp += $currentTempCelsius.ToString() + " C : " + $currentTempFahrenheit.ToString() + " F : " + $currentTempKelvin + "K"
}
return $returntemp
}
Get-Temperature
Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"
。 - Efren以管理员身份在命令提示符中运行以下命令:
wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature
这将为您提供如下输出:
CurrentTemperature 3000 3010
但请确保您正在以管理员身份运行cmd。
C*10
的单位给出,以避免传感器产生浮点数。因此,在这种情况下,您需要将传感器值除以10,并将其用于C = K - 273.15
中的K。 - not2qubit你可以使用 Open Hardware Monitor,这是一款开源软件(根据 MPL v2 许可证)。你可以在此处访问命令行版本:
以下是输出结果的示例部分:
PS C:\Users\myuser\OpenHardwareMonitorReport> .\OpenHardwareMonitorReport.exe
Open Hardware Monitor Report
--------------------------------------------------------------------------------
Version: 0.8.0.2
--------------------------------------------------------------------------------
Common Language Runtime: 4.0.30319.42000
Operating System: Microsoft Windows NT 6.2.9200.0
Process Type: 32-Bit
--------------------------------------------------------------------------------
Sensors
|
+- HP 00F52W (/mainboard)
|
+- Intel Core i7-3770 (/intelcpu/0)
| +- Bus Speed : 99.7734 99.7734 99.7784 (/intelcpu/0/clock/0)
| +- CPU Core #1 : 3691.62 3691.62 3791.58 (/intelcpu/0/clock/1)
| +- CPU Core #2 : 3691.62 3691.62 3791.58 (/intelcpu/0/clock/2)
| +- CPU Core #3 : 3791.39 3791.39 3891.36 (/intelcpu/0/clock/3)
| +- CPU Core #4 : 3691.62 3691.62 3891.36 (/intelcpu/0/clock/4)
| +- CPU Core #1 : 42 42 43 (/intelcpu/0/temperature/0)
| +- CPU Core #2 : 43 37 43 (/intelcpu/0/temperature/1)
| +- CPU Core #3 : 42 35 42 (/intelcpu/0/temperature/2)
| +- CPU Core #4 : 45 41 45 (/intelcpu/0/temperature/3)
| +- CPU Package : 45 43 45 (/intelcpu/0/temperature/4)
在我的笔记本电脑上,以上所有方法都给出了错误的结果。只有这个方法能以摄氏度显示CPU温度:
$data = Get-WMIObject -Query "SELECT * FROM Win32_PerfFormattedData_Counters_ThermalZoneInformation" -Namespace "root/CIMV2"
@($data)[0].HighPrecisionTemperature
有了新的传感器,或者使用我已经有的和高度信息。 它还显示关键温度和百分比(以摄氏度为单位)。 它生成一个名为Temperatures.txt的文件,以便轻松调试,并提供序列化对象的xml文件。
function Get-Temperature {
$TempFormat = "#"
$TempFile = "temperature"
$Command = 'Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" ' + " > $pwd\$TempFile.txt"
$Command = 'Get-WmiObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi" ' + " | Export-Clixml $pwd\$TempFile.xml"
$p = Start-Process -Verb runas -FilePath "powershell" -ArgumentList $command -WorkingDirectory $pwd -PassThru
$p.WaitForExit()
$t = Import-Clixml pippo.xml
$returntemp = @()
foreach ($Sensor in $t)
{
$Active = if($sensor.Active){"On "}else{"Off"}
$temp = $Sensor.CurrentTemperature
$Critical = $Sensor.CriticalTripPoint
$currentTempKelvin = $temp / 10
$currentTempCelsius = $currentTempKelvin - 273.15
$currentTempFahrenheit = (9/5) * $currentTempCelsius + 32
$StrKelvin = $currentTempKelvin.ToString($TempFormat).PadLeft(3, " ")
$StrCelsius = $currentTempCelsius.ToString($TempFormat).PadLeft(3, " ")
$StrFahrenheit = $currentTempFahrenheit.ToString($TempFormat).PadLeft(3, " ")
$CriticalKelvin = $Critical / 10
$CriticalCelsius = $CriticalKelvin - 273.15
$CriticalFahrenheit = (9/5) * $CriticalCelsius + 32
$StrCritKelvin = $CriticalKelvin.ToString($TempFormat).PadRight(3, " ")
$StrCritCelsius = $CriticalCelsius.ToString($TempFormat).PadRight(3, " ")
$StrCritFahrenheit = $CriticalFahrenheit.ToString($TempFormat).PadRight(3, " ")
$PerCrit = ($currentTempCelsius/$CriticalCelsius * 100)
$StrPerCrit = $PerCrit.ToString($TempFormat).PadLeft(3, " ")
$returntemp += "$Active $StrPerCrit% $StrCelsius/$StrCritCelsius C : $StrFahrenheit/$StrCritFahrenheit F : $StrKelvin/$StrCritKelvin K - " + $Sensor.InstanceName
}
return $returntemp
}
Get-Temperature
# script to get the current CPU temperature, needs to run as admin/system
# requires an external DLL from the GitHub-Project "LibreHardwareMonitor"
# on first execution the script downloads the DLL from the gitHub-Project
# carsten.giese@googlemail.com
#Requires -RunAsAdministrator
cls
$dll = "$env:windir\system32\LibreHardwareMonitorLib.dll"
$storeDll = $true
if (!(Test-Path $dll)) {
$web = [System.Net.WebClient]::new()
# download the package:
$url = "https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/releases/download/v0.9.2/LibreHardwareMonitor-net472.zip"
$zip = $web.DownloadData($url)
# extract the dll:
Add-Type -AssemblyName System.IO.Compression
$stream = [System.IO.Memorystream]::new()
$stream.Write($zip,0,$zip.Length)
$archive = [System.IO.Compression.ZipArchive]::new($stream)
$entry = $archive.GetEntry('LibreHardwareMonitorLib.dll')
$bytes = [byte[]]::new($entry.Length)
[void]$entry.Open().Read($bytes, 0, $bytes.Length)
# check MD5:
$md5 = [Security.Cryptography.MD5CryptoServiceProvider]::new().ComputeHash($bytes)
$hash = [string]::Concat($md5.foreach{$_.ToString("x2")})
if ($hash -ne 'd4a02aa7bd43a5c5ffd3d673bb20b54d') {break}
# save the dll:
if ($storeDll) {
[System.IO.File]::WriteAllBytes($dll, $bytes)
Unblock-File -LiteralPath $dll
}
} else {
$bytes = [System.IO.File]::ReadAllBytes($dll)
if (!$storeDll) {Remove-Item $dll -Force}
}
Add-Type -LiteralPath $dll
$monitor = [LibreHardwareMonitor.Hardware.Computer]::new()
$monitor.IsCPUEnabled = $true
$monitor.Open()
foreach ($sensor in $monitor.Hardware.Sensors) {
if ($sensor.SensorType -eq 'Temperature' -and $sensor.Name -eq 'CPU Package'){
$temp = $sensor.Value
break
}
}
$monitor.Close()
write-host "CPU-Package Temperature = $temp°C" -f y
要获取CPU(和每个核心)的确切温度,您需要编写内核驱动程序,这更加复杂。
CurrentTemperature返回位于主板某个热区的温度。
这就解释了为什么此页面上的某些答案会返回一个温度,但它与实际的CPU温度相差甚远。