Search code examples
c#windows-mobilewindows-mobile-6compact-framework.net-cf-3.5

Reboot Windows Mobile 6.x device programmatically using C#


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#?


Solution

  • 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);
    }