最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
VB.NET实现关机和重新启动
时间:2022-07-02 11:18:09 编辑:袖梨 来源:一聚教程网
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer
Const EWX_FORCE As Short = 4
Const EWX_LOGOFF As Short = 0
Const EWX_REBOOT As Short = 2
Const EWX_SHUTDOWN As Short = 1
Dim retval As Integer
' 定义Esc按键
Const VK_ESCAPE As Short = &H1Bs
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
If Option1.Checked Then
' 注销当前用户
retval = ExitWindowsEx(EWX_FORCE, 0)
ElseIf Option2.Checked Then
' 关闭计算机
retval = ExitWindowsEx(EWX_SHUTDOWN, 0)
ElseIf Option3.Checked Then
' 重新启动
retval = ExitWindowsEx(EWX_REBOOT, 0)
End If
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
Me.Close()
End Sub
' 按Esc键时,结束应用程序
Private Sub Form1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
If KeyAscii = VK_ESCAPE Then
Me.Close()
End If
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub
本实例通过使用ExitWindowEx()API函数来达到关机和重新启动的目的。在ExitWindowEx()函数中,参数uFlags指定要进行何种操作。在表86-2中列出了参数uFlags的值及其说明。
表86-2 参数uFlags的值及说明
常量名
值
说明
EWX_FORCE
4
终止所有进程,包括没有响应的进程,并注销Windows
EWX_REBOOT
2
重新启动系统
EWX_SHUTDOWN
1
关闭系统
EWX_LOGOFF
0
终止所有正在运行的进程,并注销Windows
Const EWX_FORCE As Short = 4
Const EWX_LOGOFF As Short = 0
Const EWX_REBOOT As Short = 2
Const EWX_SHUTDOWN As Short = 1
Dim retval As Integer
' 定义Esc按键
Const VK_ESCAPE As Short = &H1Bs
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
If Option1.Checked Then
' 注销当前用户
retval = ExitWindowsEx(EWX_FORCE, 0)
ElseIf Option2.Checked Then
' 关闭计算机
retval = ExitWindowsEx(EWX_SHUTDOWN, 0)
ElseIf Option3.Checked Then
' 重新启动
retval = ExitWindowsEx(EWX_REBOOT, 0)
End If
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
Me.Close()
End Sub
' 按Esc键时,结束应用程序
Private Sub Form1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
If KeyAscii = VK_ESCAPE Then
Me.Close()
End If
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub
本实例通过使用ExitWindowEx()API函数来达到关机和重新启动的目的。在ExitWindowEx()函数中,参数uFlags指定要进行何种操作。在表86-2中列出了参数uFlags的值及其说明。
表86-2 参数uFlags的值及说明
常量名
值
说明
EWX_FORCE
4
终止所有进程,包括没有响应的进程,并注销Windows
EWX_REBOOT
2
重新启动系统
EWX_SHUTDOWN
1
关闭系统
EWX_LOGOFF
0
终止所有正在运行的进程,并注销Windows
相关文章
- 《无限暖暖》围巾蚯蚓具体作用介绍 12-24
- 《无限暖暖》星夜守望连衣裙获得方法介绍 12-24
- 《无限暖暖》魔物试炼幻境解锁方法介绍 12-24
- 《无限暖暖》磐岩晶石获得方法介绍 12-24
- 《无限暖暖》巨石岩仔打法攻略分享 12-24
- 《无限暖暖》布布果在哪 12-24