Trả lời

6

Bạn nên sử dụng các tài liệu ExitWindowsEx API. IOCTL chỉ nên được sử dụng trên nền tảng thiếu lệnh gọi hàm ExitWindowsEx (Pocket PC 2000, 2002 và 2003). Xem MSDN doc để biết thêm thông tin.

[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); 
} 
+0

Cảm ơn rất nhiều! btw, bạn nghĩ gì về 'SetSystemPowerState' được tìm thấy ở đây: http://www.krvarma.com/windows-mobile/how-to-soft-reset-windows-mobile-programmatically/ – abatishchev

+1

Dường như thay thế hợp lệ cho ExitWindowsEx . SetSystemPowerState linh hoạt hơn và được hỗ trợ trên các nền tảng cũ hơn ExitWindowsEx. SetSystemPowerState có vẻ như chức năng sử dụng nếu bạn đang nhắm mục tiêu Windows CE hoặc hỗn hợp của các thiết bị Windows CE & Pocket PC và Windows Mobile. –

+0

+1 Tuyệt vời, cảm ơn – Tim

3

Tôi nghĩ rằng điều này sẽ giúp bạn: Hard Reset Windows Mobile Device ..Vẫn phương pháp này không phải là "mã C# rõ ràng", vì nó sử dụng Interop, nhưng nó hoạt động, để nó có thể giải quyết vấn đề của bạn.
Đối mềm reset:

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

(tho tôi đã không sử dụng phương pháp này myself..see here)

+0

tôi cần phải làm reset mềm, nghĩa là chỉ khởi động lại. Đặt lại cứng đặt lại thiết bị về mặc định – abatishchev

+0

..Mã được cài đặt để đặt lại mềm quá .. – 0x49D1

+0

Mã này hoạt động tốt trên Motorola Symbol Micro Kiosk MK500. –

4

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

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