none
如何寫程式控制pda軟開機 RRS feed

解答

  • Imports System
    Imports System.Runtime.InteropServices

    Public Class cReset
        Public Const FILE_DEVICE_HAL As Integer = &H101
        Public Const FILE_DEVICE_CONSOLE As Integer = &H102
        Public Const FILE_DEVICE_PSL As Integer = &H103
        Public Const METHOD_BUFFERED As Integer = 0
        Public Const METHOD_IN_DIRECT As Integer = 1
        Public Const METHOD_OUT_DIRECT As Integer = 2
        Public Const METHOD_NEITHER As Integer = 3
        Public Const FILE_ANY_ACCESS As Integer = 0
        Public Const FILE_READ_ACCESS As Integer = &H1
        Public Const FILE_WRITE_ACCESS As Integer = &H2

        Public Shared 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 'CTL_CODE


        <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

        Declare Sub SetCleanRebootFlag Lib "coredll.dll" ()

        Public Shared Sub WarmBoot()

            Dim bytesReturned As Integer = 0
            Dim IOCTL_HAL_REBOOT As Integer = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
            KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, bytesReturned)

        End Sub

     

          Public Shared Sub ColdBoot()

            Dim bytesReturned As Integer = 0
            Dim IOCTL_HAL_REBOOT As Integer = CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
            SetCleanRebootFlag()
            KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, bytesReturned)

        End Sub 'TestProc

    End Class

    2007年9月15日 下午 03:55