Just paste this code into a module named basExitWindows (or any other name you might desire).
'----------------------------------------------------------------------
'
' Module Name: basExitWindows
' Written By: C&D Programming Corp.
' Create Date: 10/6/97
' Copyright: Copyright 1997 by C&D Programming Corp. Source
' code may not be reproduced except for use in a
' compiled executable. All rights reserved. If
' you would like to reprint any or all of this
' code please email us at info@codeoftheweek.com
'
' Purpose: Implement a series of routines to allow Visual
' Basic programs to shutdown Windows in an orderly
' manner
'
'----------------------------------------------------------------------
Option Explicit
Public Declare Function ExitWindowsEx Lib "user32" _
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Const EWX_LOGOFF = 0 ' All processes are forced to terminate
' and the user is logged off.
Const EWX_SHUTDOWN = 1 ' The computer system is shut down to
' where it is safe to physically turn
' the power off.
Const EWX_REBOOT = 2 ' The computer system is shut down and
' rebooted.
Const EWX_FORCE = 4 ' All processes all forced to terminate.
Const EWX_POWEROFF = 8 ' The computer system is shut down and, if
' supported by the power-off feature, the
' computer is physically turned off.
' Most enabled on laptops and more
' recent energy efficient PC's.
Const EWX_RESET = EWX_LOGOFF + EWX_FORCE + EWX_REBOOT
' Logs out, forces all processes to
' terminate and resets the computer
Public Sub WinReboot()
ExitWindowsEx EWX_RESET, 0&
End Sub
Public Sub WinLogout()
ExitWindowsEx EWX_LOGOFF, 0&
End Sub
Public Sub WinPowerOff()
ExitWindowsEx EWX_POWEROFF, 0&
End Sub
Public Sub WinExitAll()
ExitWindowsEx EWX_FORCE, 0&
End Sub