How to

get battery information

Published: 20. November 2011 | Updated: 20. November 2011
License: Microsoft Public License (MS-PL)
Categories: Windows » Hardware
Tags: C# Hardware Windows Winforms
Was this snippet helpful for you? YESYES / NONO
Get Analyzant!

Check your entire website from code to content in minutes with Analyzant, the free analysis suite.

Free download at analyzant.com

Import namespace

using System.Windows.Forms;

Code

Console.WriteLine("Battery Charge Status: {0}", SystemInformation.PowerStatus.BatteryChargeStatus);
Console.WriteLine("Battery Full Lifetime: {0}", SystemInformation.PowerStatus.BatteryFullLifetime);
Console.WriteLine("Battery Life Percent: {0}", SystemInformation.PowerStatus.BatteryLifePercent);
Console.WriteLine("Battery Life Remaining: {0}", SystemInformation.PowerStatus.BatteryLifeRemaining);
Console.WriteLine("Power Line Status: {0}", SystemInformation.PowerStatus.PowerLineStatus);
Console Output:
Battery Charge Status: High
Battery Full Lifetime: -1
Battery Life Percent: 0.97
Battery Life Remaining: -1
Power Line Status: Offline
Send us feedback about this snippet »



Related Snippets: