Reboot Windows Mobile 6.x device programmatically using C#

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

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

回答1:

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


回答2:

SOFTRESET / HARDRESET

public class Reboot {     public const uint FILE_DEVICE_HAL = 0x00000101;     public const uint METHOD_BUFFERED = 0;     public const uint FILE_ANY_ACCESS = 0;      public static uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)     {         return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method);     }      [DllImport("Coredll.dll")]     public extern static uint KernelIoControl     (         uint dwIoControlCode,         IntPtr lpInBuf,         uint nInBufSize,         IntPtr lpOutBuf,         uint nOutBufSize,         ref uint lpBytesReturned     );      ///      /// Causes the CE device to soft/warm reset     ///      public static uint SoftReset()     {         uint bytesReturned = 0;         uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS);         SetCleanRebootFlag();         return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned);     }      [DllImport("coredll.dll")]     public extern static uint SetSystemPowerState     (         String psState,         Int32 StateFlags,         Int32 Options     );      const int POWER_FORCE = 4096;     const int POWER_STATE_RESET = 0x00800000;      public static uint ColdReset()     {         SetCleanRebootFlag();         return SetSystemPowerState(null, POWER_STATE_RESET, POWER_FORCE);     }      [DllImport("Coredll.dll")]     public extern static int KernelIoControl(int dwIoControlCode
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!