In Visual Basic Program You can use Windows API functions to restart your computer.
System. This document describes how to exit Windows 95 and disable the computer system.
# Shut down the computer system
You can use the exitwindowsex function of Windows API
Restart the computer system. To use this function, you must include the following statement in
In the declaration section:
Private declare function exitwindowsex lib "USER32" (byval
Uflags as long, byval dwreserved as long) as long
The exitwindowsex function requires two parameters. One or more of the following identifiers can be used.
To tell the exitwindowsex function that it wants to shut down.
All ewx_force processes are forcibly terminated.
All processes of ewx_logoff are forcibly terminated, and the user logs out (logged off ).
Ewx_poweroff: The computer system is shut down. If the power-saving feature is supported, the computer is physically shut down.
The ewx_reboot computer system is shut down and restarted.
The ewx_shutdown computer is physically shut down safely.
The following example uses the combination of the above three identifiers. This combination of identifiers
(Ewx_logoff, ewx_force, and ewx_reboot) tells Windows95 to exit all
In the running process, the user logs out of the network and logs on to the computer system.
User shutdown.
# Sample program
This example shows how to shut down the computer system.
1. Start a new project in Visual Basic and use the default method to create form1.
2. Add the following constants and declaration statements to the common declaration section of form1.
The clear statement must be written in one line ):
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
3. Add a command button control on form1 and use the default method to create comand1.
Set its caption attribute to "restart the computer ".
4. SetCodeAdd to the click event of command1:
Private sub commandementclick ()
Dim X as long
X = exitwindowsex (ewx_reset, dwreserved)
End sub
press F5 to run the preceding sample program, and click the command button to restart the computer system.