How can I shutdown a Windows Mobile device programatically
Asked Answered
A

7

3

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

Regards,

Agalloch answered 16/10, 2008 at 5:37 Comment(0)
C
4

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);
Cupriferous answered 16/10, 2008 at 12:25 Comment(0)
A
3

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

Aleydis answered 13/11, 2008 at 10:51 Comment(0)
M
1

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?

Mccollough answered 21/10, 2009 at 11:47 Comment(0)
H
0

The "normal" Windows API has ExitWindowsEx() function. You might want to check this out. It appears however that it is OEM dependant.

Hellenhellene answered 16/10, 2008 at 6:24 Comment(0)
E
0

From what I've read (a couple of years ago now) Windows CE is not actually designed to be shutdown as such, just put into a suspended low-power state. Remember its for mobile/smart phones, so they're always meant to be on.

The ExitWindowsEx function could be useful to you, but:

  • It is a native function, not .Net / Compact Framework.
  • The OEM has to implement the required functionality for it to be useful.
  • The function only exists on Windows Mobile 5.0 OS's or better, this does not mean it exists on all Windows CE devices.

Just from a personal perspective at work we've implemented our own shutdown and restart facilities for a Windows CE based OS. We had to write a lot of code for it, so I wouldn't expect this shutdown functionality to exist on all OSes.

Extrovert answered 16/10, 2008 at 6:55 Comment(0)
H
0

I have different API way of Rebooting and Powering Off(shutdown) though it has a problem not sure what.

private enum SetSystemPowerStateAction
{
POWER_STATE_ON = 0x00010000,
POWER_STATE_OFF = 0x00020000,
POWER_STATE_SUSPEND = 0x00200000,
POWER_FORCE = 4096,
POWER_STATE_RESET = 0x00800000
}

[DllImport("coredll.dll", SetLastError = true)]
static extern int SetSystemPowerState(string psState, int StateFlags, int Options);

// to off
// though am not sure why it REBOOTS??
SetSystemPowerState(null, (int)SetSystemPowerStateAction.POWER_STATE_OFF, (int)SetSystemPowerStateAction.POWER_FORCE);

// to restart
SetSystemPowerState(null, (int)SetSystemPowerStateAction.POWER_STATE_RESET, (int)SetSystemPowerStateAction.POWER_FORCE);

Hey answered 29/4, 2010 at 8:21 Comment(0)
E
0

I tried these 2 codes, successfully shutdown the handheld

Process.Start("cmd", "/c shutdown.exe")
<br/>
Me.Close()
Eskill answered 14/10, 2015 at 3:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.