Shutdown Multiple Windows Machines From The Command Prompt

Written by Saman Sadeghi on March 13, 2008 and has been viewed 1,633 views times. 15 Comments »

I’ve written about my love of batch files many times and one of my favorite tricks is shutting down a computer via the command line. In this tutorial, I will show you how to shut down multiple computers, which already connected to your network, via a batch file. This particular batch file will feature a loop that calls our shut down routine as needed!

More Information

Batch files are executed line by line, from top to bottom. By using labels, we will make the program jump around a bit. This will allow us to set a variable, call central command, then reset the variable and call the central command again. By doing this, we are only creating one variable – regardless of how many computers we have - we will just reuse that single variable. Less is more people! This method creates smaller, cleaner code: We don’t need separate variables for each computer; we just reset that variable as we need! Also, it’s important to note that each computer will use the same shutdown routine.

Before we start, you will need to make sure that you know the name of each network computer and can access it. To find out the computer’s name, walk to each machine and hit the Windows Key+Pause/Break key and click on the Computer Name tab. Look for the value under “Full computer name:”. Once you know the name of each computer connected to the network (that you’d like to remotely shut down), the easiest way to see if you can access them is with the command prompt: Go to your machine (the one that will be running the command file, not the networked machines), hit the Windows Key+R, and type:
\\{computer name}
For example, if the networked computer’s name is “274D”, you would enter:
\\274D
If the computer’s shared directory is displayed, then you’re connected! If you get an error, then you need to check connectivity settings and those are beyond the scope of this article.

Creating The File

Save Text File As .batOpen Notepad and save the file, on your Desktop, as “Network Shutdown.bat” (or “I love ham”, it’s your choice :razz: ). Make sure you set the “Save as type” drop down to “All files”.

Listing Each Computer

Right-click your newly created batch file and click Edit (double-clicking it will launch the file). We need to list all of our computers in blocks. Each block be composed of three lines of code: We will set a variable with the network computer’s name, call the loop and then create a new label with that computer’s name:
set varcomputer=274D
goto loop
:274D

Let me explain what each line means:

  1. set varcomputer=274D
    By using the “set” command, we are creating a variable called “varcomputer”, we then set the variable. In this case, with the value “274D”
  2. goto loop
    We are telling the program to go to the label named “loop”, which we will create in a few steps.
  3. :274D
    This label has the value of the computer in this block. The loop below will tell the program to go to this label, then the program will continue on the next line (line by line, remember?!).

Create a block for each computer that you’d like to shutdown:
set varcomputer=274D
goto loop
:274D

set varcomputer=322A
goto loop
:322A

set varcomputer=bobs_pc
goto loop
:bobs_pc

Notice that we are reusing the varcomputer variable. After you’ve listed each computer, write the “exit” command. This will tell the computer that we are all done and it may close the progam:
exit

Creating The Loop

The loop will consist of four parts: a label, some information for the user, the actual shutdown command and the return for the loop:
:loop
echo Shutting down %varcomputer%.
shutdown -s -m \\%varcomputer% -t 600 -c "The computer is shutting down. Please save your work."
goto %varcomputer%

    Again, let’s break down each section:

  1. :loop
    This is the entrance for the loop. The second line of each computer block is sent to this label.
  2. echo Shutting down %varcomputer%.
    This is the information that is returned to the user who runs the program; it reads the current value of the “varcomputer”. This information will not be displayed on the networked machine.
  3. shutdown -s -m \\%varcomputer% -t 600 -c "The computer is shutting down. Please save all of your work."
    This is the shutdown command. It contains a few a few parts. For detailed information on each switch, please read Windows Tip: Shutdown Your Computer With The Command Prompt
  4. goto %varcomputer%
    This is the return for the loop. The program reads the current value of the “varcomputer” variable, returns to the final line of the current block and continues to the next block. By using the goto command, we are telling the program to return to a label – one that we’ve set with the “varcomputer” variable.

The Finished Product

Now that we are armed with this knowledge, we can put it all together – but before we do, let’s add a few finishing touches. At the beginning of your file, add this:
@Echo off
This will hide all commands from the user’s view and will only display comments (that are preceded by “echo”). Also, you’ll notice there are a few lines that are started with “rem”. These are internal comments that are not processed by the program. I’ve peppered the file with a couple for you to marinate on.

Your batch file should look like this:
@Echo off
cd\
Echo Saman=Program
REM ****************************
REM * Program Variables *
REM ****************************

set varcomputer=274D
goto loop
:274D

set varcomputer=322A
goto loop
:322A

set varcomputer=bobs_pc
goto loop
:bobs_pc

Exit

REM ****************************
REM * Program *
REM ****************************

:loop
echo Shutting down %varcomputer%.
shutdown -s -m \\%varcomputer% -t 600 -c “The computer is shutting down. Please save your work.”
goto %varcomputer%

Cancel The Shut Down

You can cancel a shut down that is in progess with the following line. This line cannot be run through the network! You have to walk to each machine and run the command either from the command prompt or the Run dialog, or Windows Key+R:
Shutdown -a

Start Slide Show with PicLens Lite PicLens

Megaman Loves These Related Posts:


Megaman
  • Windows Tip: Shutdown Your Computer With The Command Prompt
  • Windows Tip: Log Off Your Computer With A Shortcut
  • Windows Tip: Shutdown Your Computer With A Batch File
  • Customize The Command Prompt
  • Windows Hacks: Improve The Context Menu, Part 4


  • iPhone: Apple on the Go

    Written by randrus on February 5, 2008 and has been viewed 765 views times. 10 Comments »

    There I was sitting in Honolulu thinking to myself that it was about time to pick up a decent digital camera.  I’ve always enjoyed photography and own a nice 35mm SLR, but I hadn’t joined the digital world yet because I didn’t want to “downgrade” my camera (I can’t afford one of those fancy Digital SLR camera’s yet)  But I’m in Hawaii….You can’t run around without a digital camera there, so it was time to bite the bullet and pick up a simple point and shoot digital camera.  Now I’ve always despised phone cameras, the quality is terrible and you can barely make out faces.  I try and avoid using mine as much as possible.  So during the lunch break, I was out with Saman and guys at the mall, and like everytime Saman and I go anywhere near an Apple store, we stopped in to see the new toys.  This was the first time I’d ever actually held the iPhone in my hands and played with it.  And sure enough within a day or two I picked one up and justified the purchase by claiming it was my camera.

    The Camera was one of the first things that impressed me with this new wonder toy.  With a two megapixel digital camera, the quality is actually good enough to use for some real pictures.  (Now don’t get me wrong, I’d still take a 7 or 8 megapixel camera any day of the week, but 2 is enough to actually get some decent 5×7 prints from)  The greatest feature of this little marvel camera, happens to be that it IS a phone camera, I find that I always have a good camera with me now and can take pictures of things that I would otherwise have missed out on.

    On the bad side, the camera does have a few limitations and issues.  1) No Movies, still frames only…I personally don’t take many movies anyway so it wasn’t a big set back. 2) Self portraits are pretty much not happening.  The soft button that you use to take the picture is in a great location when you’re looking at your target, but when trying to take your own picture, it’s nearly impossible to actually press that button and hold the camera pointed at you at the same time. 3) No zoom, at all, period.  You have to frame the picture by where you stand, 9 times out of 10 you can deal with it, but every once in a while, it would be really nice to be able to zoom in or out a touch.

    Other features that I love about the iPhone:

    1) Google maps.  It’s so nice to have a mobile reference when walking around the streets of cities that I don’t really know.  Downside is that there is no GPS.  The locate me feature is nice, but leaves you wanting a bit more.

    2) Contact management.  Something I think everyone forgets about the iPhone, the contact management system syncs great with Address Book on your mac, and is incredibly complete.  I can call, text, email all from my iPhone, I can also store address information, Instant messaging screen names, notes, and even a photo all in the same address book that I sync between my iPhone and computer.  The downside here is that you are missing a couple of key features, like being able to organize the groups directly on the iPhone, currently I have to organize groups on my computer.  And also being able to assign ringtones to groups…key feature, I can’t believe it’s not around yet.

    3) iPod on your phone, got to love it.  Now I’m never without my tunes.  Too bad they don’t have the 160gb model yet….

    4) Slide to Unlock..  I love bar phones, I’ve never particularly cared for flip phones, but the one problem I’ve always had, is accidental dialing even when I lock my phone.  The iPhone is the first phone that I’ve never had a problem with.  I’ve only had an accidental dial once, and that’s because I didn’t lock my phone before putting it back in my pocket.

    Overall I love my iPhone, but there are a few things that really do need to be fixed/added/improved before the device will really live up to it’s potential, but in the mean time I haven’t found anything else that can even compare with the feature set and simple interface that the iPhone currently offers.  Personally I’m going to be really excited to see the 2nd generation of the iPhone..maybe iPhone Air?

    MMMMM... Related Posts


    Homer
  • iPhone Teaser Ad
  • Apple Announces iPhone At MacWorld 2007
  • iPhone Autopsy
  • Would You Install A iPhone Plugin For Your Blog?
  • 45 Minutes With The iPhone


  • Sick at CES

    Written by Saman Sadeghi on January 10, 2008 and has been viewed 652 views times. No Comments »

    Today was the last day of CES and I was finally able to walk some of the show floor - I say “some” because it’s so massive. I had intended on doing a lot of pictures and reviews, just like CES 2007, but being sick doesn’t help - and I forgot to bring my camera to Las Vegas :cry:

    On top of that, Stephen Fung added me to the guest list for his party and I just wasn’t well enough to go! Oh well, maybe next year…

    Start Slide Show with PicLens Lite PicLens

    Racoon Mario Suggests You Read These Related Posts:


    Racoon Mario
  • Sick As A Dog
  • Saman’s Head On Leo Chiang’s Body
  • Atlanta Auto Show: Lexus LF-C Convertible Concept Car
  • CES 2007: Microsoft Booth
  • CES 2007: Sony Booth


  • Free File and Disk Monitor utility form Syinternals

    Written by Ajith on December 21, 2007 and has been viewed 1,065 views times. 1 Comment »

    This is a guest post by Ajith K Punnoose from Simple Informations. You might have noticed that Saman hasn’t been posting too often lately, he is concentrating in his studies. So I got this wonderful opportunity to do a guest post here. Hope you all find this useful.

    Sysinternals, previously an independent site, has got a lot of utilities to fine-tune your Windows box. Sysinternals is now a part of Microsoft.

    File Monitor from Sysinternals is a free disk read write monitoring utility. It is an out of the box program that needs no installation. It can be downloaded from the File Monitor page at Sysinternals and is a zip archive of only 279Kb. File Monitor has got a simple and clutter free interface which shows the current disk activity. The columns in the main Window shows : Time, Process that is doing the operation, Request by the process, File being accessed and Other information.

    File Monitor from Sysinternals - a screen shot

    You can set File Monitor to monitor selected drives or all the drives. The Details History can be adjusted from 1 to infinite number.You can also search in the history, apply Filters and Save the Logs. The Memory usage is 5.3Mb + 43Mb of virtual memory.

    It is a must have for System administrators and power users. File Monitor was created by Mark Russinovich and Bryce Cogswell. Download FileMonitor zip file - 279Kb.

    I blog about almost the same things as Saman but am a student and has only recently moved to my new home at exnol.com. So please tell me your valuable feedback about my blog and how I can improve the content and the appearance.

    Start Slide Show with PicLens Lite PicLens

    Ryu Says 'Read These Related Posts!'


    Ryu
  • Saman’s Big Ole List Of Windows XP Run Commands
  • Create a Startup Menu With Different Boot Options
  • Windows Tip: Automate Hard Drive Cleaning
  • Windows Tip: Start Your Day With A Fresh Computer, Step Two: Automate Hard Drive Cleaning
  • Contest On John Chow.com: Win a 24″ Wide Screen LCD Monitor


  • New Theme!

    Written by Saman Sadeghi on November 28, 2007 and has been viewed 1,037 views times. 9 Comments »

    Samanathon.com is using a new theme, come check it out!

    Ryu Says 'Read These Related Posts!'


    Ryu
  • New Theme
  • WordPress Theme Generator
  • Welcome To The New Samanathon.com!
  • New Theme
  • Mario Theme Played Using An RC Car And Glass Bottles