Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取CMD/powershell中的CPU温度_Powershell_Cmd_Cpu_Temperature - Fatal编程技术网

获取CMD/powershell中的CPU温度

获取CMD/powershell中的CPU温度,powershell,cmd,cpu,temperature,Powershell,Cmd,Cpu,Temperature,在我的电脑里,我试图得到CPU的温度。在StackOverflow上搜索时,我发现以下内容: C:\WINDOWS\system32>wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature 但我得到了这个错误: Node - ADMIN ERROR: Description = Not supported 您可以使用以下代码: function Get-Temperatur

在我的电脑里,我试图得到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

您可以通过WMI和其他方式获取CPU温度

开放式硬件监视器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenHardwareMonitor.Hardware;
namespace Get_CPU_Temp5
{
   class Program
   {
       public class UpdateVisitor : IVisitor
       {
           public void VisitComputer(IComputer computer)
           {
               computer.Traverse(this);
           }
           public void VisitHardware(IHardware hardware)
           {
               hardware.Update();
               foreach (IHardware subHardware in hardware.SubHardware) subHardware.Accept(this);
           }
           public void VisitSensor(ISensor sensor) { }
           public void VisitParameter(IParameter parameter) { }
       }
       static void GetSystemInfo()
       {
           UpdateVisitor updateVisitor = new UpdateVisitor();
           Computer computer = new Computer();
           computer.Open();
           computer.CPUEnabled = true;
           computer.Accept(updateVisitor);
           for (int i = 0; i < computer.Hardware.Length; i++)
           {
               if (computer.Hardware[i].HardwareType == HardwareType.CPU)
               {
                   for (int j = 0; j < computer.Hardware[i].Sensors.Length; j++)
                   {
                       if (computer.Hardware[i].Sensors[j].SensorType == SensorType.Temperature)
                               Console.WriteLine(computer.Hardware[i].Sensors[j].Name + ":" + computer.Hardware[i].Sensors[j].Value.ToString() + "\r");
                   }
               }
           }
           computer.Close();
       }
       static void Main(string[] args)
       {
           while (true)
           {
               GetSystemInfo();
           }
       }
   }
}
我在这里找到了一个很好的教程,我成功地获得了CPU温度


使用新传感器,或使用我现有的传感器和高程。 它还显示临界温度和百分比(以摄氏度为单位) 它留下了一个文件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

您可以使用开放硬件监视器,它是一种开源软件(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)
  • 指向命令行版本所在问题的链接 链接:
  • 更新版本的挂起拉取请求:

以管理员身份在命令提示符下运行以下命令:

wmic/namespace:\\root\wmi路径MSAcpi\u ThermalZoneTemperature获取当前温度

这将为您提供如下输出:

CurrentTemperature 3000 3010


但是,请确保您是以管理员的身份在我的笔记本电脑上运行cmd。以上所有操作都给了我错误的结果。只有这一个以摄氏度为单位显示CPU温度:

$data = Get-WMIObject -Query "SELECT * FROM Win32_PerfFormattedData_Counters_ThermalZoneInformation" -Namespace "root/CIMV2"
@($data)[0].HighPrecisionTemperature

我猜,每个CPU版本可能有不同的位置/公式来获得正确的CPU温度。

“不受支持”-其他任何东西都无法在这台机器上工作。BIOS根本不支持读取它。这不是直接的CPU温度,而是MB上的某个位置:Admin或no Admin没有区别。显然,我的Windows.Import-Clixml pippo.xml不支持该查询pippo.xml在哪里创建?
$data = Get-WMIObject -Query "SELECT * FROM Win32_PerfFormattedData_Counters_ThermalZoneInformation" -Namespace "root/CIMV2"
@($data)[0].HighPrecisionTemperature