Click here to Skip to main content
12,698,024 members (26,480 online)
Click here to Skip to main content
Add your own
alternative version


162 bookmarked

Windows Mobile Power Management

, 22 Mar 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Collection of information on interacting with the power manager to take advantage of or disable power saving features in Windows Mobile devices.


As a regular reader of the MSDN support forums and other online development communities, I see several questions (some reoccurring) about the aspects of power management and control on Windows Mobile devices. Sometimes, a developer wants to reduce the demand on power, and at other times, disable the power saving features. Then, there are coding patterns that contribute to killing the battery much faster. In response to the voices of the community, I've collected information on Windows Mobile power management. While Windows Mobile Standard devices are mentioned within this document, it is centered around Windows Mobile Professional. Power management is a huge area to cover, and there is much I have to discuss and add to this article. However, at this point, I feel that the information presented can be helpful to a number of people, and I have decided to make the article available with the plans on evolving it over a period of time until it reaches a point at which I feel it is complete. If the article becomes too large, then it may be broken into more than one article.

About the Code

The code examples included with this article are a collection of small programs that demonstrate one or two power management concepts. These programs rely on several native calls. Rather than declare P/Invokes in each individual program, there is a single project that contains all of the necessary native calls, and the example programs make their low level calls through the classes in that project. I would normally wrap these calls in a helper, but have avoided using one for these examples so as to not add a layer of separation between the calls that I wish to demonstrate. All of the sample code is in C#, with P/Invoke calls. Since the APIs used are listed, the information should be useful to C++ developers as well.

The example programs in the attached code illustrates the following:

  • Displaying the voltage, current, and temperature of your device's battery
  • Changing the power state of hardware within the device
  • Enumerating the hardware in a Windows Mobile Professional device
  • Enumerating the power modes that a Windows Professional device supports
  • Preventing a device from sleeping
  • Toggling the state of the screen's backlight
  • Waking up the machine to perform work without alerting the user or turning on the screen

Driver Dependencies

As mentioned, some aspects of power management deal with low level calls. As such, some code examples may not work on your device because of dependencies on the driver implementation. During the course of collecting this information, I performed a firmware update on a Windows Mobile 6 device I own (now a 6.1 device). Some examples stopped working, and the cause of the problem was that the manufacturer of this specific device decided not to use the standard power manager in their firmware update. Many of the code examples will run on Windows Mobile 5 devices, but I am targeting Windows Mobile 6. Running certain examples on Windows Mobile 5 may cause a "NotSupported" exception to be thrown. Within the next week, I plan to resolve any Windows Mobile 5 compatibility problems.

Terms: Windows Mobile Professional and Windows Mobile Standard

Some parts of the information within this article are specific to Windows Mobile Professional and Windows Mobile Standard. Rather than use these terms to refer to these device classes, I am reverting to the older names for these platforms. For devices that do not have a touch screen, I will use the term Smartphone instead of Windows Mobile Standard device. For devices with a touch screen, I will use the term Pocket PC instead of Windows Mobile Professional device. While these terms are considered obsolete, I find that it is easier to visually distinguish the two words. When I speak of attributes that are common to both platforms, I will use the term "Windows Mobile".

What does "Off" Mean?

Foundational to this discussion is an understanding of what is meant by the word "off". A typical light bulb on a typical light switch is either on or off, with no states in between. Historically, that could be said of many electrical devices, but in today's world, many devices do not frequently use true off states unless their power supply is disrupted. The off state has been displaced be a suspended state or low power state. The power behavior on Smartphone and Pocket PC devices are different, so I'll describe these separately. But, common amongst both platforms is that if I ever say that the device is "Off", that means that power is not flowing through the devices, while when a typical user says "off", they will mean that the device screen is off irrespective of whether or not the device is actually consuming power or performing actions.


Windows Mobile Standard devices are typically on. If you turn the phone to its true off state, then you won't be able to receive phone calls. If you don't interact with the device, the screen will power off and the processor will run at a lower speed, but it is still on and running. According to the Windows Mobile Team blog, having the device in an always on state contributes to better power savings. A potential problem with this mode is that a badly written program will cause the processor to consume more power than it needs to when it is idle.

Pocket PC

Windows Mobile Professional has four power modes that we should know about. In the full powered state, the device's screen and backlight are on. If you press the power button or don't interact with the device, then after so much time, it either goes into the "unattended"state or the suspended state. The device goes into the unattended state if a program specifies that it needs to continue running. In the unattended state, the device is still running, but the screen and backlight are powered down. The user would look at this as being an off state, but the device is still awake. If no programs need to continue running then the device will go into the suspended state. In the suspended state, all of the programs that had been running are still in memory, but they make no progress since the CPU is in a halted state. The final state we are concerned about is the true off state.

The Power States

System Power States

Windows Mobile devices have several predefined power states. Some of these states are specific to the Pocket PC, some to the Smartphone, and others can be found on both. The following table lists the power states, and describes what occurs to transition the device into a said power state. P means that a state is applicable to Pocket PCs, and S means the state is applicable to Smartphones.

State Name Description
On SP Full powered on state.
BacklightOff SP The user has not interacted with the system for some time. and the backlight has turned off. The timeout for this to occur is set through the backlight setting in the Control Panel.
UserIdle S This state is currently specific to Smartphone devices, but will be implemented on Pocket PCs once they switch to the always on power mode. In this state, the backlight and the screen are turned off.
ScreenOff SP In this state, the user has specifically turned the screen off. This is different from the screen being ruined off due to idleness.
Unattended P This mode is specific to Pocket PCs. The screen, backlight, and the audio are all turned off, but the programs on the device are running. This enables ActiveSync to check e-mail without alerting the user. From the user's perspective, the device is sleeping.
Resuming P When a device wakes up from sleeping, it is in this mode. The backlight and the screen are still off, and programs have a 15 second window to switch the device to another power state before the device automatically goes back to the suspended state.
Suspended P The device is sleeping and the processor is halted. The device will not come out of this state until a hardware event wakes it up.
Off SP The device is not performing any actions and is not consuming power (exception: though, in some devices, the system clock may still draw power to maintain time).

Note that programs can alter a device's transition among power states. An example of such a program is an instant messenger which may prevent a device from suspending so that it can continue to receive messages.

Device Driver Power States

The individual components of Windows Mobile Devices can have their own power states, the most noticeable of which is the screen and the backlight. The device can be on while the backlight or the screen is turned off (a common power configuration when using a media player). The power states for device drivers are named a little more abstractly.

State Description
D0 Device is fully powered
D1 Device is functional but in power savings mode
D2 Device is in standby
D3 Device is in sleep mode
D4 Device is Unpowered

Depending on the hardware and driver, some of these power states are identical. When the power state of a device needs to be changed, a request to change the state should be passed through DevicePowerNotify. Requesting a power state change doesn't guarantee that the state will be changed. The driver is still able to make its own decision on whether or not the power state will change (remember, your program is not the only program running, and isn't the only program that influences power state).

Requesting and Changing the Power State

Use the native function GetDevicePower if you need to monitor or query the power state. Instead of polling the state though GetDevicePower, your program can request notifications for power change events through RequestPowerNotifications.

If your application needs for the Windows Mobile device to stay in a certain power state, then use SetPowerRequirement to request the power state that your application needs. The OS will ensure that the power state of the device does not drop below what was requested. When the power state is no longer needed, then call ReleasePowerRequirement. To set the power state of a device driver instead of expressing minimum requirements, use SetDevicePower.

The power state of the system can be set through the native function SetSystemPowerState. The power state for individual hardware items in a Windows Mobile device can be set using SetDevicePower.

(You can also request that your program be started automatically during certain power change events. See Automatically Starting Your Application on Windows Mobile for more details.)

When you have an application that needs to run in unattended mode, use the native function PowerPolicyNotify() to inform the OS that you need for the device to continue to run without suspending. This is a reference-count API. For each call to this function with TRUE, you must also call this function with FALSE to ensure the device does not unnecessarily stay in a higher power.

Without the Power Manager

While Windows Mobile devices have use of the Power Manager, Windows CE devices may or may not. For devices that do not support the power manager API, calls to the GWES system can be used to power the system down programmatically. Only use GWES functions if the power manager API is not available. GwesPowerOffSystem suspends the system. Alternatively, we can also simulate the pressing of the power button by generating keyboard messages with the keybd_event function, as follows:

keybd_event( VK_OFF,0, KEYEVENTF_SILENT,0);

In either case, since the messages must be processed by GWES, the function calls will return, and a few more lines of code will execute before the system suspends. If you need your system to stop doing work after calling this method, then make a call to Sleep.

Enumerating Hardware

Active hardware in Windows CE devices can be found by first looking in the Registry in HKLM\Drivers\Active. A group of Registry keys with numeric names will be found at that location. Looking at the "Namestring inside of each one of those keys will give the name of an item of hardware. In the sample program CePowerState, I enumerate the hardware with the following code:

// Get the names of all of the subkeys that
// refer to hardware on the device.
RegistryKey driverKeyRoot =
string[] keyName = driverKeyRoot.GetSubKeyNames();

//We are saving this information to list for sorting later
List<string> deviceNameList = new List<string>();
for (int i = 0; i < keyName.Length; ++i)
   //Get the name of the hardware and add it to the list
   RegistryKey currentKey = driverKeyRoot.OpenSubKey(keyName[i]);
   string deviceName = currentKey.GetValue("Name") as string;
//Sort the list
//Add the list to the list box so the user can select hardware
for (int i = 0; i < deviceNameList.Count; ++i)

The sample program CePowerState will enumerate all of the hardware found in this location and allow you to directly set the power state of the hardware by calling SetDevicePower. The screen backlight is usually (but not always) named BKL1:, and the sound device is usually named WAV1:. Setting the power state of the backlight to D0 will turn it on, and D4 will turn it off. If you are playing audio and set the power state of WAV1: to D4, then the sound will no longer be heard until the power state is set back to D0. This is the code that sets the device's power state.

//Get the name of the selected hardware
string deviceName = lstDeviceList.SelectedItem as string;
//Get the power state to which the device will be changed
   typeof(CEDEVICE_POWER_STATE), lstPowerState.SelectedItem as string,true);
//deviceHandle = CoreDLL.SetPowerRequirement(deviceName, state,
                 (DevicePowerFlags)1 , IntPtr.Zero, 0);
CoreDLL.SetDevicePower(deviceName, DevicePowerFlags.POWER_NAME, state);

Registered Device Power Settings for Power States

There are default device power settings for certain power states. For example, in unattended state, my Windows Mobile Professional phone turns off the backlight on the screen but keeps the sound adapter and the GPS receiver powered on. The information on these settings can be found in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\Timeouts\State\. For each one of the power states, you will find a key. The contents of this key are string sub keys whose names match hardware on the device and whose value match a device power state (so 0x04 matches D4, which means a certain piece of hardware will be on at full power in the matching state).

Preventing the System from Powering Down

Pocket PCs will automatically progress towards their suspended states if no user actions are detected. There are times at which you may need for a device to maintain its full power state even though the user isn't directly interacting with the system (such as when listening to music with Windows Media Player). To prevent the system from powering down from being idle periodically, make calls to SystemIdleTimerReset(). Calling this function prevents the suspend timeout from being reached. The suspend timeouts can be changed on a system, so you will need to query for the suspend values and ensure that you call SystemIdleTimerReset on an interval shorter than the smallest suspend timeout value. The suspend timeout values can be acquired by calling SystemParametersInfo. This function can be used to acquire the following three timeout values:

Timeout Type Description
SPI_GETBATTERYIDLETIMEOUT Timeout from the last user input until suspend when running off of battery power.
SPI_GETEXTERNALIDLETIMEOUT Time out from the last user input until suspend when running on external power.
SPI_GETWAKEUPIDLETIMEOUT Timeout from the system powering itself on before it suspends again.

The timeout values can also be retrieved from the Registry. Look in the location [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power] for the following keys:

Key Description
BatteryPowerOff The amount of time (when running on battery) that the system will be idle before it suspends. Set to zero to disable suspending.
DisableGwesPowerOff Setting to a non-zero value disables GWES's management of system suspending.
ExtPowerOff The amount of time before system suspends when running on external power. Set to zero to disable suspending.
ScreenPowerOff The amount of time that the system will be idle before the screen powers off.
WakeupPowerOff The amount of time the system will wait on user input before suspending after waking up due to a non-user wakeup event.

The Battery State

The state of the batteries in Windows Mobile devices is available through the native method GetSystemPowerStatusEx2(). The information provided will tell you whether or not the device is connected to an external power source and an estimate of the amount of power left in the primary and backup battery (if present). The native function returns its information in a SYSTEM_POWER_STATUS_EX2 structure, and contains information not available through the managed SystemState class, such as the temperature of the battery or the instantaneous amount of power being consumed by the battery. The accuracy of the battery metrics returned is dependent on the OEM. The OEM also may have decided not to gather and return certain battery metrics, in which case, one of the xxxx_UNKNOWN values could be returned. The maximum amount of time between the OS updating its information on the battery can be found in [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\Timeouts\BatteryPoll].

In the attached sample programs, there is a program called "Battery Status"that displays the information on the battery. The top of the program displays the most important data on the battery: its current capacity, whether or not it is connected to an AC source, the battery's temperature, the voltage output, and the battery's current (note that the sign on the current will change when the device is charging).


The Microsoft.WindowsMobile.Status.SystemState class can also be used to monitor power state and receive notification of battery changes. The information available from the SystemState class is lower resolution (it describes battery status in terms of Very Low, Low, Medium, High, and Very High, whereas the native function returns the batter power as a percentage). The SystemState class also does not return information on power consumption or battery temperature.

Preserving Power

If you would like to ensure that your programs act responsibly and don't unnecessarily burn through the battery's power, then the best thing that your program can do is to stop performing work when no work needs to be performed. Sounds like common sense, doesn't it? But, you would be surprised with the unnecessary amount of work that programs do when they could save power by doing nothing. The most common power burning pattern I came across in the support forums is continuous polling. An example of such an implementation follows:


The above code is written with the intention of running a long running process on another thread and waiting on it to complete in the main thread without impacting the responsiveness of the main thread. If there is no work for the main thread to do, then the CPU is unnecessarily burning cycles waiting for the other thread to continue. The better alternative is to have a background task signal.

Problem "Iterative Checking"


A thread needs to wait for an event to occur before moving on to perform the rest of its actions. Many developers will create a Boolean variable and will change its value when the other thread can continue. The waiting thread pools this variable until it changes, then it continues its task.


The waiting thread is unnecessarily polling a variable and burning through CPU cycles while not accomplishing any work.


There are already facilities to implement this same functionality, provided by the runtime and the Operating System through various synchronization objects. Synchronization techniques could be used instead to block a thread until a task is complete or another thread signals for it to complete. A program can also wait on an external event, or register itself to be started during a certain external event (such as the device being connected to power, or an ActiveSync session being initialized). For these situations, the program can register to be notified or started up when the event occurs. When polling is the only way to query for status, then consider putting your thread to sleep between checks.

A discussion on the synchronization articles deserves its own place. I've written about them in another article. I've written about them here.

Example: NoPolling

For a simple example, I will use delegates and the thread pool to perform my long running tasks. The delegates are necessary since UI elements cannot be updated from a secondary thread and delegates can be used to ensure UI updates occur on the correct thread. The complete program can be found in the attached sample code.

delegate void UpdateStatusDelegate(int progress);
delegate void VoidDelegate();

UpdateStatusDelegate _updateStatus;
VoidDelegate _taskComplete;
WaitCallback _longRunningTask;

public Form1()
    _longRunningTask = new WaitCallback(LongRunningTask);
    _updateStatus = new UpdateStatusDelegate(UpdateStatus);
    _taskComplete = new VoidDelegate(TaskComplete);

// We cannot update UI elements from secondary threads. However
// the Control.Invoke method can be used to execute a delegate
// on the main thread. If UpdateStatus is called from a secondary
// thread it will automatically call itself through Control.Invoke
// to ensure its work is performed on the primary (UI) thread.
void UpdateStatus(int progress)
    if (this.InvokeRequired)
        BeginInvoke(_updateStatus, new object[] { progress });
        this.txtFeedback.Text = progress.ToString();
        pbWorkStatus.Value = progress;

// The long running task is contained within this method.
// as the task runs it will pass progress updates back to
// the UI through the UpdateStatus method. Upon completion
// of the task a call is made to TaskComplete
void LongRunningTask(object o)
        for (int i = 0; i < 100; ++i)
    catch (ThreadAbortException exc)
        //The task is being cancelled.

// Since the actions the program takes at completion of the long
// running task touch UI elements the TaskComplete method will
// also call itself (if necessary) through Control.Invoke to
// ensure that it is executing on the primary (UI) thread.
void TaskComplete()
    if (this.InvokeRequired)
        pbWorkStatus.Value = 0;
        miWork.Enabled = true;
        txtFeedback.Text = "Complete";

// When the user selects the menu item to begin working
// I will disable the work menu item to prevent concurrent
// request and start the long running progress on a secondary
// thread.
private void miWork_Click(object sender, EventArgs e)

    miWork.Enabled = false;

private void miQuit_Click(object sender, EventArgs e)

Problem "Don't Let the Device Sleep"


A program is performing a long running task that does not require user interaction such as GPS navigations (for which the user would probably look at the screen but not touch it). After the program has run for an amount of time, the screen turns off and disrupts the user's experience.


Since the user is not interacting with the system, it does as it normally should, and is powering the device down to save power.


Call the native function SystemIdleTimerReset() periodically to prevent the device from powering down.

Example Program: PreventSleep

The program "PreventSleep"reads the idle timeout values from the Registry and will call SystemIdleTimeReset at an interval that is slightly shorter than the shortest timeout. As a result, for as long as PreventSleep is running, the device will not go to sleep due to lack of user interaction.

In the code example, SystemIdleTimeReset is called on a timer so that the main thread does not need to concern itself with maintaining the resets.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Win32;
using Microsoft.Win32;

namespace PreventSleep
    public partial class Form1 : Form
        public Form1()

        // Look in the registry to see what the shortest timeout
        // period is. Note that Zero is a special value with respect
        // to timeouts. It indicates that a timeout will not occur.
        // As long as SystemIdleTimeerReset is called on intervals
        // that are shorter than the smallest non-zero timeout value
        // then the device will not sleep from idleness. This does
        // not prevent the device from sleeping due to the power
        // button being pressed.
        int ShortestTimeoutInterval()
            int retVal = 1000;
            RegistryKey key = Registry.LocalMachine.OpenSubKey(
            object oBatteryTimeout = key.GetValue("BattPowerOff");
            object oACTimeOut = key.GetValue("ExtPowerOff");
            object oScreenPowerOff = key.GetValue("ScreenPowerOff");

            if (oBatteryTimeout is int)
                int v =  (int)oBatteryTimeout;
                    retVal = Math.Min(retVal,v);
            if (oACTimeOut is int)
                int v = (int)oACTimeOut;
                    retVal = Math.Min(retVal, v);
            if (oScreenPowerOff is int)
                int v = (int)oScreenPowerOff;
                    retVal = Math.Min(retVal, v);

	//Since the interval is in seconds and out timer
	//operates in milliseconds the value needs to be multiplied
	//by 1000 to get the appropriate millisecond value. I've
	//multiplied by 900 instead so that I ensure that I call
	//SystemIdleTimerReset before the timeout is reached.
            return retVal*900;

        private void Form1_Load(object sender, EventArgs e)
            // Set the interval on our timer and start the
            // timer. It will run for the duration of the
            // program
            int interval = ShortestTimeoutInterval();
            resetTimer.Interval = interval;
            resetTimer.Enabled = true;

        private void miQuit_Click(object sender, EventArgs e)

        // Call the SystemIdleTimerReset method to prevent the
        // device from sleeping
        private void resetTimer_Tick(object sender, EventArgs e)

Problem "Wake up and Quietly Work"


Your program needs to wake up and perform some work at a predetermined time.


When the device wakes up and your program begins to work, placing the device in a full powered mode will unnecessarily get the attention of the user, or may lead to screens and buttons receiving key presses if the device were in the user's problem. We need to wake up the device without powering up the screen. The user should be totally unaware that the device is doing any work.


When the device wakes up, the program should promptly place the Windows Mobile device in unattended mode. In this mode, if the user were not using the device, then the device's screen is not going to power up, yet the program is able to run as though the device were fully powered. Once the program completes its work, it can release its requirement for the device to be in unattended mode, and can go back to sleep with the user never being made aware that the device had done anything.

Example Program: Work Quietly

WorkQuietly allows the user to select a sound file and a time delay when started. After selecting the "Run"menu option, the program will schedule for a restart of itself using the CeRunAppAtTime native call, as described in a previous article on scheduled launches of programs and terminate. After the selected time delay, the program will start and play a sound. Playing a sound is a complete contradiction of the program's name, but it is the most noticeable thing to do to prove to someone that the program is working.

This is one of the rare cases in which I modify the Main() method of a project. When an application is started because of scheduling, the command line argument "AppRunAtTime" is passed. The default implementation of the Main() method doesn't accept command line arguments. When the AppRunAtTime argument is found, instead of loading the form, I have the application play its sound and quit.

// Schedule the execution of the program and terminate.
// You can either put the device to sleep or leave it at
// full power. In either case the program will run at its
// assigned time, play a sound, and then terminate
private void miRun_Click(object sender, EventArgs e)
   int waitTime = int.Parse(this.cboStartTime.Text);
    DateTime startTime = DateTime.Now.AddSeconds(waitTime);
    string targetExecutable =
    RunAppAtTime(targetExecutable, startTime);
    using (StreamWriter sw = new StreamWriter(targetExecutable + ".soundPath"))

The following is my modified Main method:

static void Main(string[] args)
    if (args.Length == 0)
        Application.Run(new Form1());
    else if (args[0].Equals("AppRunAtTime"))
        string soundPath;

        // We started due to a scheduled event
        CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, -1);
        string targetExecutable =

        StreamWriter argInfo = new StreamWriter(targetExecutable + ".argument.txt");

        using (StreamReader sr = new StreamReader(targetExecutable + ".soundPath"))
            soundPath = sr.ReadToEnd();
        if (File.Exists(soundPath))
            Aygshell.SndPlaySync(soundPath, 0);
        CoreDLL.PowerPolicyNotify(PPNMessage.PPN_UNATTENDEDMODE, 0);

Problem "Your Program Needs to Query the Power Level of the Battery"

Being able to query the power level of the battery is useful for creating Windows Mobile utilities and for making programs that respond responsibly to available power levels.

Example Program: BatteryStatus

The process of acquiring the battery status information is incredibly simple. The P/Invoke declaration and a helper function are displayed below:

public static extern int GetSystemPowerStatusEx2(
      SYSTEM_POWER_STATUS_EX2 statusInfo,
     int length,
     int getLatest

public static SYSTEM_POWER_STATUS_EX2 GetSystemPowerStatus()
  int result =  GetSystemPowerStatusEx2( retVal, Marshal.SizeOf(retVal) , 0);
  return retVal;

The parameter getLatest controls whether or not cached information is returned or more updated information is returned. The cached information is typically no older than 5 seconds, so I see no need to demand more recent information. If you would like to ensure that your information is always up to date, then pass a non-zero value for the getLatest parameter. The sample program displays the most interesting information up top with icons, and displays all of the values returned by the function in a list box below the graphics. The information at the top includes the battery charge left, the voltage output of the battery, the battery temperature, the current being consumed, and whether or not the battery is running off of AC power. Note that the sign on the current may change between positive and negative when the battery goes from charging to discharging.

WiMoPower1/WiMoPower1004.jpg WiMoPower1/WiMoPower1005.jpg

Curiosity: What Power States are Supported on my Device

I stumbled across some interesting Registry keys while searching for other information, which resulted in this program. Using the Registry, this program will list your device's power states. Selecting one of the power states will cause the program to inform you of the default power state for the device drivers along with the hardware that should have some state other than the default.


Example Program: MyPowerStates

The code for this does nothing more than a filtered Registry dump. Here's the source code of the main part of the program:

const string BASE_POWER_HIVE = @"System\CurrentControlSet\Control\Power\State";
string[] _powerStateNames = {"Full Power","Power Savings",
                             "Standby","Sleep Mode",
                             "Power Off"};

Regex _targetRegistryValue = new Regex("(DEFAULT)|(^.*:$)",

string[] GetPowerStateList()
    RegistryKey powerStateKey = Registry.LocalMachine.OpenSubKey(BASE_POWER_HIVE);
    return powerStateKey.GetSubKeyNames();

string[][] GetPowerStateInfo(string stateName)
    RegistryKey stateInformationKey =
      BASE_POWER_HIVE, stateName));
    string[] valueList = stateInformationKey.GetValueNames();
    List<string[]> StateInfo = new List<string[]>();
    for (int i = 0; i < valueList.Length; ++i)
        string currentValue = valueList[i];
        if (_targetRegistryValue.IsMatch(currentValue))
            StateInfo.Add(new string[] { valueList[i],
              _powerStateNames[(int) stateInformationKey.GetValue(currentValue)]});
    return StateInfo.ToArray();

void PopulatePowerState()
    string[] stateList = GetPowerStateList();
    List<string> sortList = new List<string>(stateList);

    for (int i = 0; i < sortList.Count; ++i)

Getting Power Change Notifications

If you would like to receive notifications on changes in the device's power state you can register for notifications from the power manager. Doing so will require an understanding of native synchronization events and queues.  Please refer to the article Windows Mobile Interprocess Communication with Queues in .NET.


As mentioned, this document is a work in progress that I've decided to share since I feel it will be helpful to the community. Over the next several weeks, the document will be edited and example programs will be added. If there is something you would like to see, don't hesitate to make a request. Just leave a message below. If you like this article, then please rate it.

Resources and References

API References

Articles and Blog Entries

Name Author
Automatically Start your Program on Windows MobileJoel Ivory Johnson
Windows Mobile Native Thread Synchronization for .NETJoel Ivory Johnson
Windows Mobile Interprocess Communication with Message Queues in .NET Joel Ivory Johnson
Power to the SystemMike Calligaro
How Windows CE Bus Drivers WorkDavid Liao
Keeping your UI Responsive and the Dangers of Application.DoEventsJFo


  • Programming Windows Embedded CE 6.0, Douglas Boling, Microsoft Press Copyright 2008
  • Mobile Development Handbook, Andy Wigley, David Moth, Peter Foot, Microsoft Press Copyright


  • 28 August 2008
    • Initial publication
  • 14 September 2008
    • Updated example code to include the SystemState class
  • 21 March 2009
    • Corrected error in code
    • Added reference to article on native events and queues


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Joel Ivory Johnson
Software Developer Razorfish
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering.

For the past few years I've been providing solutions to clients using Microsoft technologies for web and Windows applications.

While most of my articles are centered around Windows Phone it is only one of the areas in which I work and one of my interests. I also have interest in mobile development on Android and iPhone. Professionally I work with several Microsoft technologies including SQL Server technologies, Silverlight/WPF, ASP.Net and others. My recreational development interest are centered around Artificial Inteligence especially in the area of machine vision.


You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Paul Heil8-Oct-10 6:22
memberPaul Heil8-Oct-10 6:22 
GeneralMy vote of 5 Pin
softwareservizi@1-Sep-10 23:58
membersoftwareservizi@1-Sep-10 23:58 
GeneralExcellent Pin
St. Kaevin1-Sep-10 1:40
memberSt. Kaevin1-Sep-10 1:40 
GeneralMy vote of 5 Pin
Davorin Sajnovic28-Jul-10 23:28
memberDavorin Sajnovic28-Jul-10 23:28 
QuestionWiFI always on? Pin
Davorin Sajnovic28-Jul-10 23:27
memberDavorin Sajnovic28-Jul-10 23:27 
GeneralGetting Cell ID with Unattended mode Pin
Ralph Varjabedian29-Apr-10 22:59
memberRalph Varjabedian29-Apr-10 22:59 
GeneralProcessor speed Pin
pavands15-Apr-10 8:09
memberpavands15-Apr-10 8:09 
GeneralRe: Processor speed Pin
Joel Ivory Johnson15-Apr-10 8:28
memberJoel Ivory Johnson15-Apr-10 8:28 
GeneralRe: Processor speed Pin
pavands15-Apr-10 21:42
memberpavands15-Apr-10 21:42 
AnswerRe: Processor speed Pin
Paul Heil29-Jul-10 8:06
memberPaul Heil29-Jul-10 8:06 
QuestionBacklight device name "usually" BKL1: but not always Pin
morkFlarm#11-Mar-10 13:40
membermorkFlarm#11-Mar-10 13:40 
QuestionBacklight brightness reduction Pin
pavands9-Mar-10 23:45
memberpavands9-Mar-10 23:45 
GeneralPower management - reverted Pin
valenci2-Mar-10 3:33
membervalenci2-Mar-10 3:33 
GeneralRe: Power management - reverted Pin
Joel Ivory Johnson2-Mar-10 5:33
memberJoel Ivory Johnson2-Mar-10 5:33 
QuestionHow to switch off backlight, lock keys, but keep device on ? Pin
Robeys28-Feb-10 7:06
memberRobeys28-Feb-10 7:06 
QuestionOther Functionalities that can be used?? Pin
pavands24-Feb-10 20:29
memberpavands24-Feb-10 20:29 
AnswerRe: Other Functionalities that can be used?? Pin
Joel Ivory Johnson25-Feb-10 10:05
memberJoel Ivory Johnson25-Feb-10 10:05 
GeneralRe: Other Functionalities that can be used?? Pin
pavands25-Feb-10 18:29
memberpavands25-Feb-10 18:29 
GeneralRe: Other Functionalities that can be used?? Pin
Joel Ivory Johnson25-Feb-10 19:16
memberJoel Ivory Johnson25-Feb-10 19:16 
GeneralRe: Other Functionalities that can be used?? Pin
pavands26-Feb-10 0:14
memberpavands26-Feb-10 0:14 
GeneralBacklight reduction Pin
pavands2-Mar-10 19:22
memberpavands2-Mar-10 19:22 
GeneralGreat article Pin
krokus66617-Feb-10 6:20
memberkrokus66617-Feb-10 6:20 
GeneralGPS device Pin
Std_Net5-Feb-10 3:12
memberStd_Net5-Feb-10 3:12 
GeneralReference to Win32 Pin
HaraldHeide2-Jan-10 13:35
memberHaraldHeide2-Jan-10 13:35 
GeneralRe: Reference to Win32 Pin
Joel Ivory Johnson2-Jan-10 15:47
memberJoel Ivory Johnson2-Jan-10 15:47 
Generalkeys enabled in unattended mode Pin
tilo2316-Dec-09 23:18
membertilo2316-Dec-09 23:18 
GeneralRe: keys enabled in unattended mode Pin
Joel Ivory Johnson17-Dec-09 1:42
memberJoel Ivory Johnson17-Dec-09 1:42 
GeneralI found good article "Keep Backlight ON" for Windows CE 5.0, Windows CE 6.0 and Windows Mobile Pin
thewizardcode11-Dec-09 7:06
memberthewizardcode11-Dec-09 7:06 
GeneralBattery 100% Pin
JDBP1-Dec-09 14:00
memberJDBP1-Dec-09 14:00 
GeneralRe: Battery 100% Pin
Joel Ivory Johnson2-Dec-09 3:15
memberJoel Ivory Johnson2-Dec-09 3:15 
GeneralRe: Battery 100% Pin
JDBP2-Dec-09 5:33
memberJDBP2-Dec-09 5:33 
QuestionBacklight default values Pin
Jose Cunha26-Oct-09 5:37
memberJose Cunha26-Oct-09 5:37 
AnswerRe: Backlight default values Pin
Joel Ivory Johnson26-Oct-09 6:04
memberJoel Ivory Johnson26-Oct-09 6:04 
GeneralTwo thumbs up! :) Pin
Ronny Gydar22-Oct-09 9:57
memberRonny Gydar22-Oct-09 9:57 
GeneralExcellent...... Pin
Amit Rote10-Jul-09 2:10
memberAmit Rote10-Jul-09 2:10 
GeneralRe: Excellent...... Pin
Amit Rote16-Jul-09 23:47
memberAmit Rote16-Jul-09 23:47 
GeneralMy Backlight flashes... Pin
Rafal Sobczuk3-Jul-09 3:16
memberRafal Sobczuk3-Jul-09 3:16 
GeneralRe: My Backlight flashes... Pin
Joel Ivory Johnson4-Jul-09 20:13
memberJoel Ivory Johnson4-Jul-09 20:13 
GeneralRe: My Backlight flashes... Pin
Rafal Sobczuk5-Jul-09 9:48
memberRafal Sobczuk5-Jul-09 9:48 
GeneralRe: My Backlight flashes... Pin
Joel Ivory Johnson5-Jul-09 15:16
memberJoel Ivory Johnson5-Jul-09 15:16 
GeneralKeeping the Backlight on in Windows Embedded CE 6.0 Pin
Joel Ivory Johnson18-Jun-09 6:07
memberJoel Ivory Johnson18-Jun-09 6:07 
Generalvery good job... Pin
PavanPareta4-Mar-09 0:41
memberPavanPareta4-Mar-09 0:41 
Generalevent from the GPD0 is slowen down in unattended mode Pin
valenci3-Mar-09 7:26
membervalenci3-Mar-09 7:26 
QuestionAlarm clock Pin
BaGRoS28-Feb-09 15:56
memberBaGRoS28-Feb-09 15:56 
QuestionShortestTimeoutInterval code path question Pin
_eymre_26-Feb-09 13:53
member_eymre_26-Feb-09 13:53 
AnswerRe: ShortestTimeoutInterval code path question Pin
decoda21-May-09 19:07
memberdecoda21-May-09 19:07 
GeneralGreat Work!!! Pin
niktram18-Feb-09 13:15
memberniktram18-Feb-09 13:15 
GeneralRe: Great Work!!! Pin
Joel Ivory Johnson18-Feb-09 13:34
memberJoel Ivory Johnson18-Feb-09 13:34 
QuestionHow to keep Internet connectivity while in suspend mode? Pin
Nagasava27-Jan-09 9:30
memberNagasava27-Jan-09 9:30 
QuestionWake up and Quietly Call? Pin
PaulAn11-Jan-09 0:15
memberPaulAn11-Jan-09 0:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 22 Mar 2009
Article Copyright 2008 by Joel Ivory Johnson
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid