Option Explicit
Declare Function ExitWindowsEx& Lib "user32" _
(ByVal uFlags&, ByVal wReserved&)
'//constants needed to exit Windows
Global Const EWX_LOGOFF = 0
Global Const EWX_SHUTDOWN = 1
Global Const EWX_REBOOT = 2
Global Const EWX_FORCE = 4
'*******************SHUT DOWN*********************
Sub TurnOffXP()
'shutdown.exe will NOT work on Windows 95, 98, 98 SE and ME
ActiveWorkbook.Save
Application.DisplayAlerts = False
Application.Quit
'//shut down the computer
Shell "shutdown -s -t 02", vbHide
End Sub
Sub TurnOffPC()
Dim Action As Long
ActiveWorkbook.Save
Application.DisplayAlerts = False
'//shut down the computer
Action = ExitWindowsEx(EWX_SHUTDOWN, 0&)
Application.Quit
End Sub
'***************************************************
'*********************REBOOT***********************
Sub RebootXP()
'shutdown.exe will NOT work on Windows 95, 98, 98 SE and ME
ActiveWorkbook.Save
Application.DisplayAlerts = False
Application.Quit
'//re-boot the computer
Shell "shutdown -r -t 02", vbHide
End Sub
Sub ReBootPC()
'will not work with XP
Dim Action As Long
ActiveWorkbook.Save
Application.DisplayAlerts = False
'//re-boot the computer
Action = ExitWindowsEx(EWX_REBOOT, 0&)
Application.Quit
End Sub
'***************************************************
'*********************LOG OFF***********************
Sub LogOffXP()
'this will NOT work on Windows 95, 98, 98 SE and ME
ActiveWorkbook.Save
Application.DisplayAlerts = False
Application.Quit
'//log-off
Shell "shutdown -l -t 02", vbHide 'Ok
End Sub
Sub LogOffPC()
'this will also work with XP
Dim Action As Long
ActiveWorkbook.Save
Application.DisplayAlerts = False
'//log-off
Action = ExitWindowsEx(EWX_LOGOFF, 0&)
Application.Quit
End Sub
'***************************************************
'**********************FORCE************************
Sub ForceRebootXP()
'this will NOT work on Windows 95, 98, 98 SE and ME
ActiveWorkbook.Save
Application.DisplayAlerts = False
Application.Quit
'//force
Shell "shutdown -r -f -t 02", vbHide
End Sub
Sub ForceRebootPC()
'this also works with XP
'//emergency shut down => log-off, don't save
Dim Action As Long
ActiveWorkbook.Save
Application.DisplayAlerts = False
'//force
Action = ExitWindowsEx(EWX_FORCE, 0&)
Application.Quit
End Sub
'***************************************************
|