5
 Dim power As PowerStatus = SystemInformation.PowerStatus
 Dim percent As Single = power.BatteryLifePercent

or

PowerStatus power = SystemInformation.PowerStatus;
float percent = power.BatteryLifePercent;

(I would prefer a vb answer as that is what the application is written in but can convert so c# is fine if you dont know vb)

I understand that the above will give me the battery percentage remaining - BUT I have a tablet that is 'hot swappable' (it has a main battery then a small 5 minute battery that runs the tablet while you swap batteries on it) - how would I find the status of the second battery?

I am looking for something like SystemInformation.PowerStatus(0) but I have NO idea what I am actually trying to find and I must be having a Google block as I cannot find anything.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
GrahamTheDev
  • 22,724
  • 2
  • 32
  • 64
  • There's a WMI [`Win32_Battery`](http://msdn.microsoft.com/en-us/library/aa394074(v=vs.85).aspx) class if there's no managed access to this information. – Damien_The_Unbeliever Mar 06 '14 at 08:07
  • Look at the page http://www.csharpdeveloping.net/Snippet/how_to_enumerate_batteries_using_wmi It provides full list of the information you can get from the WMI about the batteries – Dmitriy Finozhenok Mar 06 '14 at 08:36

2 Answers2

7

You can use WMI and Win32 to get the battery levels.

Try this:

ObjectQuery query = new ObjectQuery("Select * FROM Win32_Battery");

foreach (ManagementObject o in new ManagementObjectSearcher(query).Get())
{
    uint level = (uint)o.Properties["EstimatedChargeRemaining"].Value;
} 
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
1

In case of multiple batteries, you can make use of WMI. Specifically, Win32_Battery class.However, this will be a bit slower than using PowerStatus class.

danish
  • 5,550
  • 2
  • 25
  • 28
  • Speed not an issue - will only be polling it every 2 minutes or so - just that my application is full screen so covers the status! – GrahamTheDev Mar 06 '14 at 09:15