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.

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top