NewLifeX / X

Core basic components: log (file / network), configuration (XML / JSON / HTTP), cache (memory / redis), network (TCP / UDP / HTTP), RPC framework, serialization (binary / XML / JSON), APM performance tracking. 核心基础组件,日志(文件/网络)、配置(XML/Json/Http)、缓存(内存/Redis)、网络(Tcp/Udp/Http)、RPC框架、序列化(Binary/XML/Json)、APM性能追踪。

Home Page:https://newlifex.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

部分机型读取不到电池电量

SeedSpace opened this issue · comments

机器信息如下:
"OSName": "Windows 11 专业版",
"OSVersion": "6.2.9200.0",
"Product": "HP Pavilion Gaming Laptop 17-cd1xxx",
"Processor": "Intel(R) Core(TM) i7-10870H CPU @ 2.20GHz",

用的是MachineInfo类

commented

Windows电量取自于win32_battery.EstimatedChargeRemaining,在win10+surfaceLaptop3测试没有问题。
温度则需要管理员权限运行程序。

电量代码如下:
var battery = ReadWmic("path win32_battery", "EstimatedChargeRemaining"); if (battery != null && battery.Count > 0) { if (battery.TryGetValue("EstimatedChargeRemaining", out var str)) Battery = str.SplitAsInt().Average() / 100.0; } else { if (XTrace.Log.Level <= LogLevel.Debug) XTrace.WriteLine("Battery信息无法读取"); _excludes.Add(nameof(Battery)); Battery = 0; }