win10温度获取的方法,在win11已经不行了
下面是win11获取温度代码 先安装包 LibreHardwareMonitorLib 用管理员身份运行
using LibreHardwareMonitor.Hardware;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace 硬件温度2
{
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) { }
}
internal class Program
{
public static void Monitor()
{
Computer computer = new Computer
{
IsCpuEnabled = true,
IsGpuEnabled = true,
IsMemoryEnabled = true,
IsMotherboardEnabled = true,
IsControllerEnabled = true,
IsNetworkEnabled = true,
IsStorageEnabled = true
};
computer.Open();
computer.Accept(new UpdateVisitor());
foreach (IHardware hardware in computer.Hardware)
{
Console.WriteLine("Hardware: {0}", hardware.Name);
foreach (IHardware subhardware in hardware.SubHardware)
{
Console.WriteLine("\tSubhardware: {0}", subhardware.Name);
foreach (ISensor sensor in subhardware.Sensors)
{
Console.WriteLine("\t\tSensor: {0}, value: {1}", sensor.Name, sensor.Value);
}
}
foreach (ISensor sensor in hardware.Sensors)
{
Console.WriteLine("\tSensor: {0}, value: {1}", sensor.Name, sensor.Value);
}
}
computer.Close();
}
static void Main(string[] args)
{
Monitor();
Console.ReadKey();
}
}
}