Reboot Windows Mobile 6.x device programmatically using C#

abatishchev picture abatishchev · Aug 9, 2010 · Viewed 8.5k times · Source

My HTC HD2 can't be rebooted from OS, just shut down. So I want to write a small program to do that.

Is it possible to programmatically reboot Windows Mobile 6.x device using C#?

Answer

Trevor Balcom picture Trevor Balcom · Aug 9, 2010

You should use the documented ExitWindowsEx API. IOCTL should only be used on platforms lacking the ExitWindowsEx function call (Pocket PC 2000, 2002, and 2003). See the MSDN doc for more information.

[DllImport("aygshell.dll", SetLastError=""true"")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ExitWindowsEx([MarshalAs(UnmanagedType.U4)]uint dwFlags, [MarshalAs(UnmanagedType.U4)]uint dwReserved);

enum ExitWindowsAction : uint
{
    EWX_LOGOFF = 0,
    EWX_SHUTDOWN = 1,
    EWX_REBOOT = 2,
    EWX_FORCE = 4,
    EWX_POWEROFF = 8
}

void rebootDevice()
{
    ExitWindowsEx(ExitWindowsAction.EWX_REBOOT, 0);
}