Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags as Long, ByVal wReserved as Long) as Long
Private Const EWX_FORCE = 4 'Force any applications to quit instead of prompting the user to close them.
Private Const EWX_POWEROFF = 8 'Shut down the system and, if possible, turn the computer off.
Private Const EWX_LOGOFF = 0 'Log off the network
Private Const EWX_REBOOT = 2 'Perform a full reboot of the system
Private Const EWX_SHUTDOWN = 1 'Shut down the system
'Purpose : Forces a machine shut down/logoff
'Inputs : [lShutDownType] If unspecified, will reboot the machine else one of the above constants
'Outputs : If successful returns a number other than zero
'Author : Andrew Baker
'Date : 31/01/2001 14:35
'Notes :
'Revisions :
Function MachineShutDown(Optional lShutDownType As Long = EWX_REBOOT) As Long
MachineShutDown = ExitWindowsEx(EWX_SHUTDOWN, 0&) 'shut down the computer
End Function
'Demonstration routine
Sub Test()
'Forces the computer to reboot
Call MachineShutDown(EWX_REBOOT)
'Forces the user to log off
Call MachineShutDown(EWX_LOGOFF)
'Shuts the computer down (no restart)
Call MachineShutDown(EWX_SHUTDOWN)
'Shuts the computer down and turns power off (if possible)
Call MachineShutDown(EWX_POWEROFF)
End Sub