我的HTC HD2無法從操作系統重新啓動,只需關閉。所以我想寫一個小程序來做到這一點。以編程方式使用C#重新啓動Windows Mobile 6.x設備
是否有可能以編程方式重新啓動Windows Mobile 6.x設備使用C#?
我的HTC HD2無法從操作系統重新啓動,只需關閉。所以我想寫一個小程序來做到這一點。以編程方式使用C#重新啓動Windows Mobile 6.x設備
是否有可能以編程方式重新啓動Windows Mobile 6.x設備使用C#?
您應該使用記錄ExitWindowsEx
API。 IOCTL
只能在缺少ExitWindowsEx函數調用的平臺上使用(Pocket PC 2000,2002和2003)。有關更多信息,請參閱MSDN doc。
[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);
}
我認爲這將幫助你:Hard Reset Windows Mobile Device ..仍然這種方法不是「清晰的C#代碼」,因爲它使用Interop,但它的工作原理,因此它可以解決你的問題。
對於軟復位:
[DllImport("coredll.dll", SetLastError=true)]
private static extern bool KernelIoControl(int dwIoControlCode, byte[] inBuf, int inBufSize, byte[] outBuf, int outBufSize, ref int bytesReturned);
private const uint FILE_DEVICE_HAL = 0x00000101;
private const uint METHOD_BUFFERED = 0;
private const uint FILE_ANY_ACCESS = 0;
private static uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)
{
return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method);
}
public static void softReset()
{
uint bytesReturned = 0;
uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS);
KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned);
}
(儘管我沒有用過這個方法myself..see here)
我需要做的軟復位,即只要重啓。硬復位會將設備重置爲默認設置 – abatishchev 2010-08-09 07:16:22
..也可以爲軟復位添加代碼.. – 0x49D1 2010-08-09 10:51:37
此代碼在Motorola Symbol Micro Kiosk MK500上正常工作。 – 2015-04-20 13:19:33
SOFTRESET /硬格
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
);
/// <summary>
/// Causes the CE device to soft/warm reset
/// </summary>
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, IntPtr lpInBuf, int nInBufSize, IntPtr lpOutBuf, int nOutBufSize, ref int lpBytesReturned);
[DllImport("Coredll.dll")]
public extern static void SetCleanRebootFlag();
public static void HardReset()
{
int IOCTL_HAL_REBOOT = 0x101003C;
int bytesReturned = 0;
SetCleanRebootFlag();
KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned);
}
[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);
}
非常感謝!順便說一句,你覺得'SetSystemPowerState'在這裏找到了什麼:http://www.krvarma.com/windows-mobile/how-to-soft-reset-windows-mobile-programmatically/ – abatishchev 2010-08-10 06:10:00
這似乎是一個有效的替代ExitWindowsEx 。 SetSystemPowerState功能更多,並且在早期的平臺上比ExitWindowsEx更受支持。如果您的目標是Windows CE或Windows CE和Pocket PC與Windows Mobile設備的混合,SetSystemPowerState看起來就像使用該功能。 – 2010-08-10 13:55:21
+1很好,謝謝 – Tim 2011-10-25 16:59:01