VB. NET shutdown and restart

Source: Internet
Author: User
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
'Define Esc buttons
Const VK_ESCAPE As Short = & H1Bs
Private Sub commandateclick (ByVal eventSender As System. Object, ByVal eventArgs As System. EventArgs) Handles Command1.Click
If Option1.Checked Then
'Deregistering the current user
Retval = ExitWindowsEx (EWX_FORCE, 0)
ElseIf Option2.Checked Then
'Shut down the computer
Retval = ExitWindowsEx (EWX_SHUTDOWN, 0)
ElseIf Option3.Checked Then
'Restart
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
'Press Esc to end the application
Private Sub formatekeypress (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
This instance shuts down and restarts by using the ExitWindowEx () API function. In the exitdomainwex () function, the uFlags parameter specifies the operation to be performed. The uFlags parameter value and its description are listed in table 86-2.
Table 86-2 uFlags values and descriptions
Constant name
Value
Description

EWX_FORCE
4
Terminate all processes, including processes that do not respond, and log out of Windows

EWX_REBOOT
2
Restart the system

EWX_SHUTDOWN
1
Shut down the system

EWX_LOGOFF
0
Terminate all running processes and log out of Windows


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.