ホーム > VB.NET > [VB.NETメモ] 端末の再起動コード

2010年03月23日(火曜日) 03時13分

すぐに忘れそうなのでφ(..)メモメモ

Imports System.Runtime.InteropServices

Public Class Form1

    Private Const FILE_DEVICE_HAL As Integer = &H101
    Private Const METHOD_BUFFERED As Integer = 0
    Private Const FILE_ANY_ACCESS As Integer = 0

    Private Function CTL_CODE( _
        ByVal DeviceType As Integer, _
        ByVal Func As Integer, _
        ByVal Method As Integer, _
        ByVal Access As Integer) As Integer
        Return (DeviceType << 16) Or (Access << 14) Or (Func << 2) Or Method
    End Function

    <DllImport("CoreDll.dll")> _
    Public Shared Function KernelIoControl( _
    ByVal dwIoControlCode As Integer, _
    ByVal lpInBuf As IntPtr, _
    ByVal nInBufSize As Integer, _
    ByVal lpOutBuf As IntPtr, _
    ByVal nOutBufSize As Integer, _
    ByRef lpBytesReturned As Integer) As Integer
    End Function

    Private Function ResetPocketPC() As Integer
        Dim bytesReturned As Integer = 0
        Dim IOCTL_HAL_REBOOT As Integer = _
        CTL_CODE(FILE_DEVICE_HAL, _
        15, METHOD_BUFFERED, FILE_ANY_ACCESS)
        Return KernelIoControl( _
        IOCTL_HAL_REBOOT, IntPtr.Zero, 0, _
        IntPtr.Zero, 0, bytesReturned)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim response As MsgBoxResult
        response = MsgBox("再起動します。よろしいですか?", MsgBoxStyle.YesNo, "再起動")
        If response = MsgBoxResult.Yes Then
            ResetPocketPC()
        End If
    End Sub

End Class

「[VB.NETメモ] 端末の再起動コード」 について、Twitterでつぶやく

関連記事