How to remotely shutdown, restart or logoff a Windows

January 16, 2010

This article will describe how we can remotely restart, shutdown, log off or even abort a system shutdown in our Local/Network machines using Remote Shutdown Tool (shutdown.exe).

We can use the Remote Shutdown Tool with GUI or from the command prompt but we need to have administrative privileges on those machines.

We can start the GUI of Remote Shutdown Tool by executing:—

shutdown.exe /i

If we need to use the command line tool here are the options:

Note: We can use the – switch in case / switch does not work or vice versa

Usage examples:
Restart a network machine and force any running applications to close

shutdown /m \\computername /r /f

Abort a previous shutdown command

shutdown /m \\computername /a

Shutdown a network machine and force any running applications to close

shutdown /m \\computername /s /f

Logoff a machine and force any running applications to close (This cannot be used with /m to specify the target machine)

shutdown computername /l /f

Hibernate a local machine and force any running applications to close

shutdown /m \\computername /h /f

Note: By default the time-out period in previous examples is set to 30 seconds.

Restart a network machine and force any running applications to close giving a reason and set the time-out period to 1 minute (120 sec)

shutdown /m \\computername /r /f /c “Computers will restart in 1 minute, please save any work. System Administrator” /t: 120

Schedule a restart of a machine:

at 23:00 /every:M,T,W,Th,F shutdown /r /m \\computername

In case we want to shutdown/restart multiple network machines through a batch file have a look at the following :—

This article will describe how to shutdown remote network computers by using a small batch script to loop into each hostname/ip line within a text file and issuing the shutdown command to the computer(s).

The above code will take an argument for the shutdown time which we specify while running the script:

@echo off
if “%1″==”” goto fin
for /f “tokens=1″ %%i in (computers.txt) do ^
shutdown -s -t %1 -f -m \\%%i
:fin

Explaining the above code we first check if an argument exist so it continues with the batch file else it ends.
For each hostname/ip inside the computers.txt it executes the shutdown command for each remote machine inside the network.

We could even simplify the script without asking for any arguments with the following snippet:

@echo off
for /f “tokens=1″ %%i in (computers.txt) do ^
shutdown -s -t 30 -f -m \\%%i

The -t 30 is for the time limit which by default is 30 if you do not specify that option.
The -s option shutdown the computer.
The -f option forces the application to close while the system shutdown without asking the user to interact.
The -m option is to specify the computer(s) hostname/ip.

After we finish with the batch file we can schedule it to run through a domain admin account to remotely shutdown the network computer(s) at specific times and dates.

Kuntal

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: