X icon indicating copy to clipboard operation
X copied to clipboard

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

Open SeedSpace opened this issue 2 years ago • 2 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",

SeedSpace avatar Jul 08 '22 07:07 SeedSpace

用的是MachineInfo类

SeedSpace avatar Jul 08 '22 07:07 SeedSpace

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; }

nnhy avatar Jul 10 '22 23:07 nnhy