How can I shutdown a Windows Mobile device programatically

17,223

Solution 1

It probably not a great idea to do it from your app - the device has a power button for a reason and shutting down the app can cause user confusion and frustration.

If you must do it, and you are using Windows Mobile 5.0 or later, you can P/Invoke ExitWindowsEx like this:

[Flags]
public enum ExitFlags
{
  Reboot = 0x02,
  PowerOff = 0x08
}

[DllImport("coredll")]
public static extern int ExitWindowsEx(ExitFlags flags, int reserved);

...

ExitWindowsEx(ExitFlags.PowerOff, 0);

Solution 2

OpenNetCF.WindowsCE.PowerManagement class has methods for suspending and soft reseting. It even has a method for hardware reset!

Solution 3

Another thing to note with the ExitWindowsEx API is that shutdown is only supported on Windows Mobile Standard (i.e. Smartphone) and not Windows Mobile Professional (Pocket PC) devices.

See the special notes on the EWX_POWEROFF flag within the ExitWindowsEx documentation on MSDN. I have not tried the API on Pocket PC for a couple of years, but I'm pretty sure that's still the state of play.

Instead you may like to investigate using the power management APIs to put the device into a lower power state, such as suspended, or unattended mode. What are you attempting to achieve by programatically shutting off the device?

Share:
17,223
Dean Bates
Author by

Dean Bates

Updated on June 26, 2022

Comments

  • Dean Bates
    Dean Bates almost 2 years

    I would like to programatically shutdown a Windows Mobile device using Compact framework 2.0, Windows mobile 5.0 SDK.

    Regards,