How to LogOff/Restart/Shutdown the system (in two ways)
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 'System & API - How to LogOff/Restart/Shutdown the system (in two ways) 'Using API: Option Explicit Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _ ByVal dwReserved As Long) As Long Public Const EXIT_LOGOFF = 0 Public Const EXIT_SHUTDOWN = 1 Public Const EXIT_REBOOT = 2 Public Sub ExitWindows(ByVal uFlags As Long) Call ExitWindowsEx(uFlags, 0) End Sub 'To Log Off your system: Call ExitWindows(EXIT_LOGOFF) 'To Restart your system: Call ExitWindows(EXIT_REBOOT) 'To shut down your system: Call ExitWindows(EXIT_SHUTDOWN) 'Without Using API: Option Explicit Sub Main() 'To Log off your system Shell "Shutdown.exe -l" 'To Restart your system Shell "Shutdown.exe -r" 'To shutdown your system Shell "Shutdown.exe -s" End Sub 'Other Arguments of Shutdown.exe 'Usage: ' 'shutdown.exe [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "comment"] [-d up:xx:yy] ' ' No args Display this message (same as -?) ' -i Display GUI interface, must be the first option ' -l Log off (cannot be used with -m option) ' -s Shutdown the computer ' -r Shutdown and restart the computer ' -a Abort a system shutdown ' -m \\computername Remote computer to shutdown/restart/abort ' -t xx Set timeout for shutdown to xx seconds ' -c "comment" Shutdown comment (maximum of 127 characters) ' -f Forces running applications to close without warning ' -d [u][p]:xx:yy The reason code for the shutdown ' u is the user code ' p is a planned shutdown code ' xx is the major reason code (positive integer less than 256) ' yy is the minor reason code (positive integer less than 65536) |