I have an application that gets detailed system information, and I have been able to get the percent of charge remaining but not the percent of the battery itself.
Explanation: As time goes on, the battery slowly gets worse and worse, and some applications, like Dell Support Center on Laptops, display the status of the battery, not the status of the charge, which used to be 100% but now is 90%.
How can I get this value in C# or .NET?
Don’t have a laptop to test with, but I’m guessing you could use the WMI class Win32_Battery.
It has two fields that look interesting –
DesignCapacity, which tells youand
FullChargeCapacity, which has the fascinating note thatSo my guess is that you can use WMI to read these two values, and then calculate
FullChargeCapacity/DesignCapacityto find the battery health percentage number.EDIT
Here’s a brief example of accessing WMI information using C#. I first added a reference to the
System.Managementassembly. Then:Also, note that you are basically running a SQL-like query against WMI, so you can vary that if you want.
Windows Management Instrumentation Query Language, orWQL, is what you want to search for to learn more about it.Also take a look at ahawker’s answer, it may end up being more helpful if WMI isn’t properly capturing the battery data, as he notes.