CH3COOH(酢酸)が.NET FrameworkやWindows Mobileの事を始め、日々情報を発信中!

デバイスを再起動(ソフトリセット)する

Windows Mobileでは2種類の「リセット」があります。
デバイスの再起動を行う為の「ソフトリセット」、工場出荷状態に戻すための「ハードリセット」です。

ハードリセットを行う為のAPIは存在しておらず、手動で特定のキーを押下しながらバッテリィを入れる等、特殊な操作が必要になります。今回はデバイスの再起動を行う「ソフトリセット」のご紹介です。

Win32APIであるExitWindowsEx関数を、P/Invokeにて呼び出す事によってデバイスの再起動(ソフトリセット)します。

    ' 以下の名前空間を指定しておいてください
    ' using System.Runtime.InteropServices;  
    
    <Flags()> _
    Enum ExitWindows As Integer
        Reboot = &H2
        PowerOff = &H8
    End Enum

    <DllImport("aygshell.dll", SetLastError:=True)> _
    Shared Function ExitWindowsEx(ByVal uFlags As ExitWindows, _
                                  ByVal dwReason As Integer) _
                                  As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        ' デバイスを再起動(ソフトリセット)する
        Dim isSuccess As Boolean = ExitWindowsEx(ExitWindows.Reboot, 0)

    End Sub
    // 以下の名前空間を指定しておいてください
    // using System.Runtime.InteropServices;  
    
    [Flags()]
    enum ExitWindows : int
    {
        Reboot = 0x2,
        PowerOff = 0x8
    }
    
    [DllImport("aygshell.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool ExitWindowsEx(ExitWindows uFlags, int dwReason);
    
    private void Button1_Click(System.Object sender, System.EventArgs e)
    {
        // デバイスを再起動(ソフトリセット)する
        bool isSuccess = ExitWindowsEx(ExitWindows.Reboot, 0);
    }

Copyright(C) since 2008 CH3COOH(酢酸). All Rights Reserved.