Private Declare Function ExitWindowsEx Lib user (ByVal uFlags As Integer ByVal dwReserved As Integer) As IntegerConst EWX_FORCE As Short = Const EWX_LOGOFF As Short = Const EWX_REBOOT As Short = Const EWX_SHUTDOWN As Short = Dim retval As Integer 定义Esc按键Const VK_ESCAPE As Short = &H BsPrivate Sub Command _Click(ByVal eventSender As System Object ByVal eventArgs As System EventArgs) Handles Command ClickIf Option Checked Then 注销当前用户retval = ExitWindowsEx(EWX_FORCE )ElseIf Option Checked Then 关闭计算机retval = ExitWindowsEx(EWX_SHUTDOWN )ElseIf Option Checked Then
重新启动retval = ExitWindowsEx(EWX_REBOOT )End IfEnd SubPrivate Sub Command _Click(ByVal eventSender As System Object ByVal eventArgs As System EventArgs) Handles Command ClickMe Close()End Sub 按Esc键时 结束应用程序Private Sub Form _KeyPress(ByVal eventSender As System Object ByVal eventArgs As System Windows Forms KeyPressEventArgs) Handles MyBase KeyPressDim KeyAscii As Short = Asc(eventArgs KeyChar)If KeyAscii = VK_ESCAPE ThenMe Close()End IfIf KeyAscii = TheneventArgs Handled = TrueEnd IfEnd Sub本实例通过使用ExitWindowEx()API函数来达到关机和重新启动的目的 在ExitWindowEx()函数中
参数uFlags指定要进行何种 *** 作 在表 中列出了参数uFlags的值及其说明 表 参数uFlags的值及说明lishixinzhi/Article/program/net/201311/13585
shell "C:\Windows\System32\shutdown.exe -s"
这是关闭
shell "C:\Windows\System32\shutdown.exe -r"这是重启
添加一个按钮,输入代码:
Private Sub Command1_Click()
Shell "shutdown.exe -r -t 0" '立刻重启计算机
End Sub
运行后点击按钮,电脑就会重启
评论列表(0条)