The Shutdown-Inator

One afternoon I was curious and started playing with DOS commands, specifically looking for a way to automate a computer shutdown in Windows, and what I found was the DOS shutdown command.  Now if you are familiar with DOS commands and BAT files, this is probably not anything new to you.  But I found it interesting and took it a step further creating a BAT file for shutting down computers other computers on the same local network.

So first let’s look at the command I am using to shutdown a computer on the same network and go from there.  Below is an example of a DOS command that will shutdown Computer01.

shutdown /s /m \\computer01 /t 10 /c “System Shutdown”

We start off by running shutdown, followed by /s which tells the command to do a full shutdown.  We then put in /m \\computer01 which means remote computer with a hostname of computer01.  We add /t 10, which tells the command to give it a 10 second countdown.  Finally there is /c “System Shutdown”, which tells the command to display the comment, System Shutdown.  So basically when run, this will pop up a message on Computer01 for 10 seconds and display System Shutdown before the computer powers off completely.

This all sounds really easy to do, and it is, but this is also Windows so there are a few things to look out for.  The first one is user authentication, in order for this to work smoothly it is helpful that both the computer you are running the command from and the computer you are shutting down share a common administrator level account.  In other words, you need to have a userid and password that are the same, and have administrator access on both computers.

Another gotcha you can run into is with Windows Firewall.  You should check to make sure the Firewalls of both computers will allow the command to access the remote computer.  Typically in Windows Firewall, you need to allow File and Printer Sharing on both of the computers, that should allow the shutdown command to run.  You can find the Windows Firewall by going into the Control Panel, then add an exception for File and Printer Sharing.

The other problem you could run into is, what if I log into one computer with a different userid the the remote computer.  As I said before, as long as there is a common userid and password on both computers with administrator level access, you can work around this fact.  There is another DOS command I have used called runas.  Basically I can use runas to change the userid I am running the command as, without having to login as the other user account.  Once I have used runas to change who I am running the shutdown command as, I can then remotely shutdown the other computer.  I have an example below, but for this example let’s assume I have saved the above shutdown command as a BAT file called shutdownpcs.bat, and that I have created a common Administrator account and password on both Computer01 and Computer02.

runas /user:computer02\administrator c:\shutdownpcs.bat

So when I run the above command, it changes my user level to the Administrator of Computer02, which is the common userid between both computers.  It then runs my shutdownpcs.bat which tells Computer01 to shutdown as per the example at the beginning.

I know that is a lot to take in, and I would highly recommend giving it a try.  In the environment where I work, there are a lot of public computers and this kind of remote shutdown is a big time saver., as opposed to going one by one and shutting down the computers manually.  As I said before, if you are into DOS and programming, this isn’t anything overly amazing, but it is a nice, cheap trick to use if you want to shutdown multiple computers without having to get out of your chair.