C# Windows 7 power management

Posted: July 20, 2014 in C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsAPICodePack.ApplicationServices;
using Microsoft.WindowsAPICodePack.Shell;
namespace WindowsFormsApplication2
public partial class Form1 : Form
public Form1()

private void Form1_Load(object sender, EventArgs e)

label3.Text = PowerManager.PowerSource.ToString();

BatteryState batteryState = PowerManager.GetCurrentBatteryState();
progressBar1.Value = PowerManager.BatteryLifePercent;
label1.Text = PowerManager.BatteryLifePercent.ToString() + “%”;
label9.Text = batteryState.MaxCharge + ” mWh”;
label4.Text = batteryState.CurrentCharge + ” mWh”;



we need to add references…

using Microsoft.WindowsAPICodePack.ApplicationServices;
using Microsoft.WindowsAPICodePack.Shell;



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s