Mobile 重启设备
这里有三种方式可以重启Mobile 设备
SetSystemPowerState
SetSystemPowerState
[DllImport("Coredll.dll")]
public static extern int SetSystemPowerState(string psState, SystemPowerStateFlags StateFlags, uint Options);
public const uint POWER_FORCE = 0x00001000;
public enum SystemPowerStateFlags : uint
{
POWER_STATE_ON = 0x00010000, // on state
POWER_STATE_OFF = 0x00020000, // no power, full off
POWER_STATE_CRITICAL = 0x00040000, // critical off
POWER_STATE_BOOT = 0x00080000, // boot state
POWER_STATE_IDLE = 0x00100000, // idle state
POWER_STATE_SUSPEND = 0x00200000, // suspend state
POWER_STATE_UNATTENDED = 0x00400000, // Unattended state.
POWER_STATE_RESET = 0x00800000, // reset state
POWER_STATE_USERIDLE = 0x01000000, // user idle state
POWER_STATE_BACKLIGHTON = 0x02000000, // device scree backlight on
POWER_STATE_PASSWORD = 0x10000000 // This state is password protected.
}
public static extern int SetSystemPowerState(string psState, SystemPowerStateFlags StateFlags, uint Options);
public const uint POWER_FORCE = 0x00001000;
public enum SystemPowerStateFlags : uint
{
POWER_STATE_ON = 0x00010000, // on state
POWER_STATE_OFF = 0x00020000, // no power, full off
POWER_STATE_CRITICAL = 0x00040000, // critical off
POWER_STATE_BOOT = 0x00080000, // boot state
POWER_STATE_IDLE = 0x00100000, // idle state
POWER_STATE_SUSPEND = 0x00200000, // suspend state
POWER_STATE_UNATTENDED = 0x00400000, // Unattended state.
POWER_STATE_RESET = 0x00800000, // reset state
POWER_STATE_USERIDLE = 0x01000000, // user idle state
POWER_STATE_BACKLIGHTON = 0x02000000, // device scree backlight on
POWER_STATE_PASSWORD = 0x10000000 // This state is password protected.
}
调用
NativeMethods.SetSystemPowerState(null, NativeMethods.SystemPowerStateFlags.POWER_STATE_RESET, NativeMethods.POWER_FORCE);
ExitWindowsEx
ExitWindowsEx
[DllImport("aygshell.dll")]
public static extern bool ExitWindowsEx(ExitWindowsExFlags uFlags, int dwReserved);
public enum ExitWindowsExFlags : uint
{
EWX_REBOOT = 2,
// This flag is not supported on a Windows Mobile-based Pocket PC.
EWX_POWEROFF = 8
}
public static extern bool ExitWindowsEx(ExitWindowsExFlags uFlags, int dwReserved);
public enum ExitWindowsExFlags : uint
{
EWX_REBOOT = 2,
// This flag is not supported on a Windows Mobile-based Pocket PC.
EWX_POWEROFF = 8
}
调用
NativeMethods.ExitWindowsEx(NativeMethods.ExitWindowsExFlags.EWX_REBOOT, 0);
KernelIoControl
KernelIoControl
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 bool KernelIoControl
(
uint dwIoControlCode,
IntPtr lpInBuf,
uint nInBufSize,
IntPtr lpOutBuf,
uint nOutBufSize,
ref uint lpBytesReturned
);
private bool ResetPocketPC()
{
uint bytesReturned = 0;
uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS);
return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned);
}
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 bool KernelIoControl
(
uint dwIoControlCode,
IntPtr lpInBuf,
uint nInBufSize,
IntPtr lpOutBuf,
uint nOutBufSize,
ref uint lpBytesReturned
);
private bool ResetPocketPC()
{
uint bytesReturned = 0;
uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS);
return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned);
}
posted on 2009-12-14 16:29 listenlisten 阅读(1214) 评论(14) 编辑 收藏 举报