Terminate Windows 95 in Visual Basic

Source: Internet
Author: User
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.

Related Article

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.