用VB编写关机程序怎么写呀?

来源:百度知道 编辑:UC知道 时间:2024/06/10 15:37:07

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

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"