Wednesday 2 September 2009

Windows: Shutting down machines remotely

I have many times heard people complain about Windows machines freezing or being very slow to respond. The problem sometimes is so bad that not even the desktop user is able to close frozen applications or even shutdown her own machine. The remedy for 99% of all these cases, thank you Microsoft, -- as Mark Minasi would have said -- is the notorious shutdown command.

This posting will contain a brief overview of the command syntax. This command has been around since the days of Windows NT4 but Microsoft has changed it and now in Windows 2003 environments the arguments are not the same

So, to begin with the oldest version for those of us still stuck with NT4, the syntax for this platform is like this

shutdown \\machine_name /r /t:10 "Machine is going down in 10 seconds" /y /c

You can also use the /l switch to force a local shutdown. The /c, shown above, is very useful since it forces all running applications to close. The -t:N will display a message notifying the user that their machine is going down in N seconds. Here you can also provide an additional string explaining the reasons for the reboot, enclosed in double quotes. Finally if you forget the /r then the machine will just shutdown and then you 'll have to walk over there and power it down -- remember, this is NT4 we 're talking about -- and then up yourself. If after all you change your mind and you decide that the machine does not need to reboot, then -- if there is still enough time left -- use the command shutdown \\machine_name /A to abort the shutdown process.

Now with Windows 2003 the shutdown command has changed quite a bit. The equivalant command to shutdown a remote system now looks like this:

shutdown /r /m \\machine_name /t 10 /f /c "Machine is going down in 10 seconds"

The order of the arguments is significant. The /r switch can be replaced with /s to shutdown or /a to abort a shutdown in progress. The /t and the time interval are now separated by a space instead of a column ':' character. The /c switch now introduces the message for the shutdown reason and finally /f is now used to force closing of all running applications.

Shutdown for Windows 2003 has also an additional /d [p:]xx:yy switch that allows you to specify a coded reason for the shutdown, in exactly the same way you do when shutting down a Windows 2003 server via the GUI. The shutdown help screen provides detailed code listings about the meaning of each code. I never use them from the command line, so my most often issued command looks like this :

shutdown /r /m \\pc-bakalidis /t 0 /f 

No comments :