部分机型读取不到电池电量
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类
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; }