I checked the remaining time of my laptop battery in WMI mode and got the result of 71582788 minutes. unexpectedly, the first thought was that the relevant code was wrong.
ManagementObjectSearcher s = new ManagementObjectSearcher ("select * from Win32_Battery"); ManagementObjectCollection m = s. get (); foreach (ManagementObject mo in m) {Console. writeLine (mo ["EstimatedRunTime"]. toString () + "minutes ");}
I checked several times and found no problems. I also searched for similar code on the Internet.
After being troubled for a while, I tried to unplug the power cord of my notebook and start the program again. This is not the value of 71582788.
Therefore, the conclusion is that the Code can obtain the correct result only when the external power supply is not used.
Why do we get such a strange number as 71582788 when using an external power supply?
In fact, the value obtained from the EstimatedRunTime attribute is in minutes. 71582788 minutes are converted to 4294967296 seconds, that is, 2 ^ 32. The maximum value of a 32-bit second counter is this value.
In other words, because the notebook can be used continuously in theory when the power is plugged in, EstimatedRunTime uses 71582788 minutes to indicate unlimited usage.
The above is my guess.
The final result may not be correct even if the power cord is switched out.
You can run this program several times. It is not difficult to find that the results are inconsistent each time, and the difference is large, or even the error is more than an hour.
However, this is a normal result. Because the remaining power of the notebook is originally shown in this way, the detection program of its system has the same problem. For the moment, this should be a problem that cannot be solved temporarily.
Published in my blog at the same time