Johan's Blog

This and that in a developer's life in general
Welcome to Blogs @ IRM Sign in | Join | Help
 Search

Disclaimer

The content of this site is my own personal opinion and does not in any way represent my employer, it's subsideries or affiliates. These postings are provided "AS IS" with no warranties, and confer no rights.

This Blog

[.NET 2.0] On Battery or Not

I'm thinking of writing a small utility to manage which of my apps gets started at startup of Windows, depending on if my laptop is running on batteries or not. Normally, when I boot it up on batteries, I don't want to start things such as my blog reader and a few other things.

The thing is it's very simple to detect from .NET if you are running on batteries or not. The SystemInformation type gives you all that and more:

using System;

using System.Windows.Forms;

 

namespace BatteryConsole

{

    class Program

    {

        static void Main(string[] args)

        {

            PowerStatus ps = SystemInformation.PowerStatus;

 

            if(ps.PowerLineStatus == PowerLineStatus.Online)

                Console.Write("Your power cable is connected, and ");

            else

                Console.Write("You are running on batteries, and ");

            Console.WriteLine("your battery level is on {0}", (ps.BatteryLifePercent * 100) + "%");

 

        }

    }

}

I'll get back if I ever get that small program written.


Cross-posted from my blog at http://weblogs.asp.net/jdanforth
Published den 10 november 2006 08:55 by johan
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server, by Telligent Systems