如何关闭/重新启动计算机?

  • 来源: 互联网 作者: rocket   2008-03-18/09:34
  • 16位Windows用ExitWindows() API函数,而32位Windows则用ExitWindowsEx().32位版本比16位版本多了更多的控制及选项,包括注销及关机。

    Declare Function ExitWindows Lib "user" (ByVal uFlags As Long, ByVal _
    dwReserved As integer) As integer
    Const EW_REBOOTSYSTEM = &H43
    Const EW_RESTARTWINDOWS = &H42

    Sub Command1_Click()

    Dim iAns As Integer
    Dim rVal As Integer
    Dim iButtonType as Integer

    iButtonType = 4 + 32 ' vbYesNo + vbQuestion

    ' Ask if the user is sure they want to exit.
    iAns = MsgBox("Are you sure you want to exit windows?", iButtonType, _
    "Exit Windows")
    If iAns = 6 Then ' Yes pressed
    ' Call the exit function to Reboot.
    rVal = ExitWindows(EW_REBOOTSYSTEM, 0)
    End If

    End Sub

    ***** 32位的例子 *****
    In a project with 1 commandbutton, place the following code:
    Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
    ByVal dwReserved As Long) As Long
    Private Const EWX_LOGOFF = 0
    Private Const EWX_SHUTDOWN = 1
    Private Const EWX_REBOOT = 2
    Private Const EWX_FORCE = 4

    Private Sub Command1_Click()

    Dim iAns As Integer
    Dim rVal As Long

    ' Ask if the user is sure they want to exit.
    iAns = MsgBox("Are you sure you want to exit windows?", vbQuestion Or _
    vbYesNo, "Exit Windows")
    If iAns = vbYes Then
    rVal = ExitWindowsEx(EWX_SHUTDOWN, 0&)
    End If

    End Sub


    查看ExitWindowsEx的详细用法


    评论 {{userinfo.comments}}

    {{money}}

    {{question.question}}

    A {{question.A}}
    B {{question.B}}
    C {{question.C}}
    D {{question.D}}
    提交

    驱动号 更多