Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Exiting and Restarting Windows

I am currently writing and testing an installation program which will soon be distributed. During the this process, I edit the SYSTEM.INI file. Most Windows software will allow you to "Reboot" windows to allow the new configuration to take effect. Could you please tell me the technique used in VB to make this happen? Also, could you please tell me how to exit Windows and re-boot the machine in case I make changes in the AUTOEXEC.BAT and CONFIG.SYS file?

The ExitWindows API function performs this function. The documentation for it is in the Windows 3.1 SDK help file. The one thing to note on this is that it does not override normal behavior of applications that ask to save before exiting. The ExitWindows API function, therefore, could end up not executing.

Here is an example of how to use the ExitWindows API under VB4 (32-bit). For VB3, refer to the Windows 3.1 SDK help file or the VB API Text Viewer.

1. Start a new project in Visual Basic. Form1 is created by default.

2. Add the following code to the General Declarations portion of Form1:

   Const EWX_LogOff As Long = 0
   Private Declare Function ExitWindows Lib "User32" _
      Alias "ExitWindowsEx" _
      (ByVal dwOptions As Long, ByVal dwReserved As Long) As Long

3. Add the following code to the Form_Click event:

   ExitWindows EWX_LogOff, &HFFFFFFFF

4. Save the project for future use, if desired.

5. Choose Make EXE File... from the File menu to compile the program.

6. Close all running instances of Visual Basic and run the compiled EXE.

7. Click the Form. Windows will close all running applications and log the user off from the current Windows session.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date