Rob van der Woude's Scripting Pages

Shutdown, Reboot and Logoff

A collection of shutdown commands for most DOS and Windows versions and scripting languages.

 

OS (1) Command line Effect Remarks
W10 RUNDLL32 powrprof.dll, SetSuspendState Sleep Sleep  
W7 SHUTDOWN /s /t 60 /c "Shutdown in progress, leave the vicinity immediately" Shutdown in 60 seconds, with warning message Use -m \\remote_computer to shutdown/logoff a remote computer.
W7 SHUTDOWN /p Immediate shutdown without warning
W7 SHUTDOWN /l Logoff
W7 SHUTDOWN /h Hibernate (or sleep if hibernate is disabled)
XP Pro NLTEST /server:localhost /shutdown:"Shutting down, just for fun" 60 Shutdown in 1 minute, displaying the "reason" in a popup Use a remote server name instead of localhost to shutdown that remote server.
XP Pro NLTEST /server:localhost /shutdown_abort Abort the shutdown in progress Use a remote server name instead of localhost to abort a shutdown in progress on that remote server.
XP Pro WMIC OS Where Primary=TRUE Call Shutdown Immediate shutdown Use WMIC's /NODE switch to shutdown a remote computer.
XP Pro WMIC OS Where Primary=TRUE Call Reboot Immediate reboot Use WMIC's /NODE switch to reboot a remote computer.
XP Pro WMIC OS Where Primary=TRUE Call Win32Shutdown 4 Forced logoff (0+4) n can be any of the following numbers:
0	Logoff
1	Shutdown
2	Reboot
+4	Force
8	Poweroff
XP Pro WMIC OS Where Primary=TRUE Call Win32Shutdown 12 Forced poweroff (8+4)
XP SHUTDOWN -r -t 10 Delayed reboot Reboot after a 10 seconds delay.
Can be stopped during those 10 seconds using SHUTDOWN -a
XP SHUTDOWN -s -t 01 Delayed shutdown Shutdown after a 1 second delay, NO poweroff.
XP SHUTDOWN -i Interactive use with GUI Can be used to shutdown multiple computers.
TS LOGOFF 16 /SERVER:termserv1 Logoff Logoff session 16 on Terminal Server TERMSERV1.
Use the QUERY USER command to find out which session ID belongs to whom.
Find more Terminal Server commands.
TS TSSHUTDN 45 /SERVER:termserv1 /POWERDOWN /DELAY:20 /V Delayed poweroff Notify all users on Terminal Server TERMSERV1, logoff all Terminal Server sessions after 45 seconds, wait another 20 seconds, and then shut down Terminal Server TERMSERV1 and power off.
See my Terminal Server Commands page for the exact syntax.
W2K (5) DEVCON Reboot Reboot Requires Microsoft's DEVCON utility
W2K RUNDLL32 PowrProf.dll, SetSuspendState Activate suspend state  
W2K RUNDLL32 USER32.DLL,LockWorkStation Lock Credits: Steven Clements (posted on alt.msdos.batch.nt)
NT+ (1) PSSHUTDOWN -d -t 0 Suspend Uses PSSHUTDOWN.EXE from SysInternals' PS Tools.
NT+ (1) PSSHUTDOWN \\mynt4srv -K -F -T 20 Delayed poweroff Poweroff \\mynt4srv after a 20 seconds delay.
Can be aborted using PSSHUTDOWN \\mynt4srv -A
Uses PSSHUTDOWN.EXE from SysInternals' PS Tools.
NT+ (1) PSSHUTDOWN \\myw2ksrv -O -F -T 0 Logoff Immediately logoff console user on \\myw2ksrv
Uses PSSHUTDOWN.EXE from SysInternals' PS Tools
NT4+RK
W2K+RK
SHUTDOWN /L /R /T:0 /Y Reboot Immediate shutdown & reboot
NT4+RK
W2K+RK
SHUTDOWN /L /T:10 /Y /C Delayed shutdown Shutdown in 10 seconds, close without saving.
Can be stopped during those 10 seconds using SHUTDOWN /A
NT4 See Reboot NT on my Solutions found in alt.msdos.batch page Reboot Reboot immediately
NT4 RUNDLL32 USER32.DLL,ExitWindowsEx
RUNDLL32 USER32.DLL,ExitWindowsEx
Logoff Most systems require the command to be called twice before logging off
Win98/ME RUNDLL32 SHELL32.DLL,SHExitWindowsEx n Any n can be any of the following numbers: (4):
0	Logoff
1	Shutdown
2	Reboot
+4	Force
8	Poweroff (if supported by the hardware)
Win98/ME RUNONCE.EXE -q Reboot (4)  
Win98 RUNDLL32 KRNL386.EXE,exitkernel Poweroff Poweroff for ATX boards only, otherwise normal shutdown (3)
Win9* RUNDLL USER.EXE,ExitWindows Shutdown (2)  
Win9* RUNDLL USER.EXE,ExitWindowsExec See Remarks Win95: various results, usualy fast shutdown (and lock PC), sometimes restart Windows, sometimes reboot.
Win98: Restart Windows, sometimes reboot.
Win9* RUNDLL SHELL.DLL,RestartDialog Restart dialog "System Settings Changed, Do you want to restart your computer now?" dialog
Win31* ECHO G=FFFF:0000| DEBUG Task Manager popup And sometimes reboot
DOS ECHO G=FFFF:0000| DEBUG Reboot Warm boot, sometimes cold boot.
May not work with "exotic" memory managers, like Quarterdeck's QEMM or DesqView; in that case, use RESET.COM instead.
PowerShell Restart-Computer -Force Reboot Immediately reboot the local computer.
PowerShell Restart-Computer -ComputerName "remotepc" -Confirm -Force Reboot Reboot remote computer "remotepc", prompt for confirmation on local computer first.
PowerShell Stop-Computer -Force Shutdown Immediately shutdown the local computer.
PowerShell Stop-Computer -ComputerName "remotepc" -Confirm -Force Shutdown Shutdown remote computer "remotepc", prompt for confirmation on local computer first.
PowerShell Stop-Process -ProcessName * Blue Screen Kills all running processes immediately without confirmation, resulting in a "Blue Screen Of Death".
KiXtart $RC = SHUTDOWN( "\\server", "Shutting down...", 10, 1, 0 ) Delayed shutdown Shutdown \\server in 10 seconds, with message, close without saving, no reboot
KiXtart $RC = SHUTDOWN( "\\server", "", 0, 1, 1 ) Reboot Immediately shutdown & reboot \\server, without a message
KiXtart $RC = LOGOFF( 1 ) Logoff Forcing applications to close.
Use 0 instead of 1 if you don't want to force applications to close
KiXtart $RC = SetSystemState( 0 ) Lock Requires KiXtart 4.51 or later
KiXtart $RC = SetSystemState( 1 ) Standby Requires KiXtart 4.51 or later
KiXtart $RC = SetSystemState( 2 ) Hibernate Requires KiXtart 4.51 or later.
KiXtart $RC = SetSystemState( 3, 0 ) Poweroff Power off with prompt to close applications.
Use SetSystemState( 3, 1 ) to close applications without prompting.
Requires KiXtart 4.51 or later
Perl InitiateSystemShutdown( $sComputer, $sMessage, $uTimeoutSecs, $bForce, $bReboot )   General syntax (ActivePerl for Windows only)
Perl InitiateSystemShutdown( "", "", 0, 1, 1 ) Reboot Immediately reboot without message, force applications to close without saving data
Perl InitiateSystemShutdown( "", "Going down...", 10, 0, 1 ) Delayed reboot Reboot after 10 seconds, with message and without forcing applications to close
Perl InitiateSystemShutdown( "10.0.1.16", "Sorry", 5, 1, 0 ) Delayed shutdown Shutdown of remote computer after 5 seconds, with message and forced closing of applications
Regina Rexx RC = W32SysShutdown( how [,force] )   General syntax (Regina Rexx for Windows with W32Funcs only).
how can be either Reboot, Logoff, Poweroff or Shutdown.
force can be either Force or Noforce.
Regina Rexx RC = W32SysShutdown( "P", "F" ) Poweroff Immediately shutdown and poweroff, forced closing of application
Regina Rexx RC = W32SysShutdown( "L", "N" ) Logoff Logoff, prompt for saving unsaved data
WSH [1] Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
[2]
[3]
for each OpSys in OpSysSet
[4]     OpSys.Reboot( )
[5] next
Reboot Requires WMI.
Remove [line numbers].
(by Alex K. Angelopoulos)
WSH Replace line 4 in the script above with this one:
[4]    OpSys.Shutdown( )
to shut down the PC instead of rebooting it.
Shutdown But no poweroff.
 
See my WSH page for examples on how to reboot or shut down remote computers too.
WSH [1] Const EWX_LOGOFF   = 0
[2]
[3]
Set wmi = GetObject("winmgmts:{(Shutdown)}")
[4] Set objSet = wmi.InstancesOf("Win32_OperatingSystem")
[5]
[6]
For Each obj in objSet
[7]     Set os = obj
[8]     Exit For
[9] Next
[10]
[11]
os.Win32Shutdown EWX_LOGOFF
Logoff Requires WMI.
Remove [line numbers].
(Posted by Michael Harris on microsoft.public.scripting.vbscript)
 
My Logoff.vbs combines this code with that of the reboot and shutdown commands, and allows logoff of remote computers as well.
WSH Set objShell = CreateObject( "Shell.Application" )
Shell.ShutdownWindows
Open the Shutdown dialog Based on the Advanced Stuff listing on groups.msn.com/windowsscript/.
OS/2 START /PM SHUTDOWN && EXIT Shutdown Will still stop and ask for confirmation if a non-PM application is active
OS/2 SETBOOT /B Reboot Unconditional shutdown & reboot from default Boot Manager entry.
(Mailed by Rick Curry)
OS/2 SETBOOT /IBD:C: Reboot Unconditional shutdown & reboot from C: drive
OS/2 SETBOOT /IBA:nonsense Shutdown Unconditional shutdown & failing reboot.
Needs Boot Manager installed.
Will reboot, no questions asked, and then stop if nonsense is an invalid Boot Manager menu entry (which, in this case, is exactly what we want).
OS/2 LOGOFF Logoff Both LAN Server client and Peer

 

Notes: (1) DOS MS-DOS or PC-DOS
Win31* Windows 3.1, 3.11 or 3.11 for Workgroups
  Win9* Windows 95 or 98
  Win98 Windows 98
  Win98/ME Windows 98 or Windows Millennium Edition (ME)
  NT+ Windows NT 4, 2000, XP, Vista, 7, 8, 10, 11
  NT4 Windows NT 4 (not Windows 2000, XP, etc.)
  NT4+RK Windows NT 4 with Resource Kit
  W2K Windows 2000
  W2K+RK Windows 2000 with Resource Kit
  XP Windows XP
  XP Pro Windows XP Professional and Windows Server 2003
  W7 Windows 7 (and Windows Server 2008 R2), 8, 10 and 11
  W10 Windows 10 and 11
  TS Windows NT 4 Terminal Server Edition or Windows 2000 (Advanced) Server with Terminal Server installed
  PowerShell Windows XP or later with PowerShell installed
  KiXtart Windows (any) with KiXtart
  Perl Windows (any) with ActivePerl
  Regina Rexx Windows (any) with Regina Rexx and W32Funcs
  WSH Windows (NT 4 or later) with Windows Script Host
  OS/2 OS/2 Warp 3 and 4, LAN Server and Warp Server
  (2) Thanks for Bill James and Tom Lavedas, for the information on RUNDLL.
Find more RUNDLL examples I collected on my RUNDLL page.
  (3) Thanks for Sasha Predii for posting this information.
Find more RUNDLL examples I collected on my RUNDLL page.
  (4) See article Q234216 in the Microsoft Knowledge base for more information.
Thanks for Alec Soroudi for pointing out this information.
Windows NT also has a RUNONCE.EXE, but I am not sure what its purpose is — RUNONCE.EXE -q does not shut down NT.
  (5) Requires Microsoft's DEVCON utility

FoolishIT's ShutdownUnless is a safe way to schedule server reboots, aborting the reboot if any client connections are active.

Jorgen Bosman's PowerOff for all Windows (32-bits) versions can power off, shutdown or reboot your PC, log you off, lock your workstation, go to standby or hibernation mode and even wake up another PC.
All actions can be done locally or on a remote PC (if it is running PowerOff).
The actions can be performed immediately or scheduled, by using its built-in scheduler.
This tool can be used both as a GUI or as a command line tool.

Gibson Research's Wizmo is a collection of tools integrated in a single package.
Among its functions are shutdown, reboot, hibernate and logoff.

SysInternals' PSSHUTDOWN can perform logoffs, poweroffs, shutdowns and reboots on both local and remote Windows NT 4/2000/XP systems.
A must-have for mixed Windows environments.

NirCmd is a small command-line utility that allows you to do some useful tasks without displaying any user interface.
By running NirCmd with simple command-line option, you can restart windows or shut down the computer, write and delete values and keys in the Registry, write values into INI file, dial to your internet account or connect to a VPN network, create shortcut to a file, change the created/modified date of a file, change your display settings, turn off your monitor, open the door of your CD-ROM drive, and more...

For Windows XP (and later) use the native POWERCFG command to configure Standby and Hibernate (and more).

Lock, Logoff, Reboot, Shutdown, Hibernate, Standby in .NET by Thiagarajan Alagarsamy.

How To Restart Computers Remotely via PowerShell by Jeffery Hicks


page last modified: 2023-10-30; loaded in 0.0018 seconds