How can I disconnect a Windows Mobile device programmatically

I would like to programmatically shut down a Windows Mobile device using Compact framework 2.0, the Windows Mobile 5.0 SDK.

Hi,

+3
windows-mobile compact-framework
source share
7 answers

This is probably a great idea to do this from your application - the device has a power button for some reason, and closing the application can cause confusion and frustration for the user.

If you must do this and use Windows Mobile 5.0 or later, you can P / Invoke ExitWindowsEx as follows:

[Flags] public enum ExitFlags { Reboot = 0x02, PowerOff = 0x08 } [DllImport("coredll")] public static extern int ExitWindowsEx(ExitFlags flags, int reserved); ... ExitWindowsEx(ExitFlags.PowerOff, 0); 
+4
source share

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

+3
source share

Another thing to note with the ExitWindowsEx API is that shutdown is only supported on Windows Mobile Standard (such as a smartphone) and not on Windows Mobile Professional (Pocket PC) devices.

See special notes for the EWX_POWEROFF flag in the ExitWindowsEx documentation on MSDN. I have not tried the API on Pocket PC for a couple of years, but I am sure that the state of the game is still.

Instead, you may need to research using the Power Management API to bring your device to lower power consumption, such as suspended or automatic mode. What are you trying to achieve by turning off the device programmatically?

+1
source share

There is an ExitWindowsEx () function in the "normal" Windows API. You can check it out. However, it seems to be OEM dependent .

0
source share

From what I read (a couple of years ago), Windows CE is not really designed to stop as such, it just fits in a suspended, low-power state. Remember it for mobile / smartphones, so they should always be included.

The ExitWindowsEx function may be useful to you, but:

  • This is a built-in function, not a .Net / Compact Framework.
  • OEM must implement the necessary functions to be useful.
  • The function exists only in Windows Mobile 5.0 or higher, this does not mean that it exists on all Windows CE devices.

From a personal point of view at work, we have implemented our own means of stopping and restarting for Windows CE-based operating systems. We had to write a lot of code for it, so I did not expect this stop function to exist on all OSs.

0
source share

I have another API way to reboot and shutdown, although it has a problem, I don't know 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);

// off off
// although not sure why it is 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);

0
source share

I tried these 2 codes, successfully turned off the PDA

 Process.Start("cmd", "/c shutdown.exe") <br/> Me.Close() 
0
source share

All Articles