Terminate Win9x in VB

zhaozj2021-02-11  190

Terminate Win9x in VB

In the Visual Basic program, you can use the Windows API function to restart your computer system. Text describes how to exit Windows 9X and turn off your computer system. First, turn off computer system

You can restart your computer system from the Visual Basic program using the Windows API's exitwindowsex function. To use this function, you need to contain the following statement statements in the usual declaration section of the form:

Private Declare Function ExitWindowSex Lib "User32" (Byval dwreserved as long) AS Long

The EXITWINDOWSEX function requires two parameters, and a combination of one or more of the following identities can be used to tell the exitwindowsex function to make a shutdown process.

EWX_FORCE All processes are mandatory to terminate.

EWX_LOGOFF All processes are forced to terminate and the user exits logged off.

The EWX_POWEROFF computer system is turned off and the computer is physically shut down if the power save feature is supported.

The EWX_REBOOT computer system is turned off and restarted.

The EWX_SHUTDOWN computer is physically safely shut down.

The combination of three identities above is used in the sample program. This identity combination (EWX_LOGOFF, EWX_FORCE,, and EWX_REBOOT "tells Windows 95 to exit all processed processes and use the user to exit the network login, so that the computer system is ready for the user to shut down.

2. Sample program

The sample program shows how to turn off the computer system.

1. Start a new project in Visual Basic, build FORM1 with the default method.

2. Add the following constants and declaration statements to the usual declaration section of Form1 (note that the declaration statement needs to be written within one line):

Private Declare Function ExitWindowSex Lib "User32" (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 to establish COMAND1 with the default method. Set its CAPTION property to "Restart Computer".

4, add the following code to Command1 Click Event:

Private submmand1_click ()

DIM X as long

X = exitwindowsex (ewx_reset, dwreserved)

End Sub

Press F5 to run the above sample program, click the Command button to restart your computer system.

The above code from: the source code database (SourceDataBase) Current Version: 1.0.445 Author: Shawls profile: Http://Shawls.Yeah.Net E-Mail: ShawFile@163.Net QQ: 9181729

转载请注明原文地址:https://www.9cbs.com/read-4841.html

New Post(0)