September 5, 1995
In a Microsoft® Visual Basic® program, you can use a Microsoft Windows® application programming interface (API) function to reboot the computer system in various ways. This article explains how to quit Windows 95 and shut down the computer system.
You can use the Microsoft® Windows® application programming interface (API) ExitWindowsEx function to reboot a computer system from within a Microsoft Visual Basic® application. To use this function, include the following Declare statement in the General Declarations section of your form:
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags
As Long, ByVal dwReserved As Long) As Long
The ExitWindowsEx function takes two arguments—the shutdown operation you want performed, and a parameter that is not used. You can use one or more combinations of the following flags to tell the ExitWindowsEx function how you want to perform the shutdown procedure.
EWX_FORCE | All processes all forced to terminate. |
EWX_LOGOFF | All processes are forced to terminate and the user is logged off. |
EWX_POWEROFF | The computer system is shut down and, if supported by the power-off feature, the computer is physically turned off. |
EWX_REBOOT | The computer system is shut down and rebooted. |
EWX_SHUTDOWN | The computer system is shut down to where it is safe to physically turn the power off. |
In the example program below, you use a combination of three of the above flags. This flag combination (EWX_LOGOFF, EWX_FORCE, and EWX_REBOOT) tells Windows 95 to quit all currently executing processes, log the user off network connections, and leave the computer system ready for the user to turn off.
This program shows how to shut down the computer system.
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long,
ByVal dwReserved As Long) As Long
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const EWX_POWEROFF = 8
Const EWX_RESET = EWX_LOGOFF + EWX_FORCE + EWX_REBOOT
Private Sub Command1_Click()
Dim X As Long
X = ExitWindowsEx(EWX_RESET, dwReserved)
End Sub
Run the example program by pressing f5. Click the command button to reboot the computer system.
"ExitWindowsEx." (MSDN Library, SDK Documentation, Platform SDK)