TechJunkie is a BOX20 Media Company

Home PC Windows Quickly Shut Down or Reboot a Remote PC with a Custom Batch File

Quickly Shut Down or Reboot a Remote PC with a Custom Batch File

Quickly Shut Down or Reboot a Remote PC with a Custom Batch File

We’ve previously looked at how you can use the shutdown command via the Windows Command Prompt to shut down and reboot remotely connected PCs. Once you understand how the command works, using the shutdown command and its various parameters is relatively quick and easy, but if you frequently connect to the same remote PC, you can save some time by creating your own shut down or reboot batch file. Here’s how.
For those unfamiliar with the concept, batch files (also known as batch programs or scripts) are raw text files that contain one or more command line instructions. A user can create a batch file by typing desired commands in order, and then the computer will execute each command in sequence when the file is run. Batch files can greatly simplify repetitive tasks, allowing users to craft potentially complex command line instructions just once and then repeatedly run the commands as needed with just a click.
There are a multitude of uses for batch files, but we’re focusing today on creating a relatively simple file that will shut down or reboot our remotely connected Windows PC with the desired options and parameters. To get started, first take a minute to review how the shutdown command works, including its primary parameters.
Next, while connected to the remote PC, create a new blank text document in Notepad (note: you can create your shutdown or reboot batch file on any computer and then manually transfer it to the remote PC, but creating it directly on the remote PC saves a step).
With your blank Notepad document open, craft your reboot or shut down command. In our example, we want our batch file to reboot our remote PC, force all open applications to close, and reboot immediately without a time delay. Based on the appropriate command parameters for the shutdown command, we’ll therefore type the following into our Notepad document:

shutdown -r -f -t 0

create reboot batch file
To recap, the shutdown command is used for both shutting down a PC and rebooting it based on the correct parameter. In this case, using -r tells the command that we want to reboot. The -f parameter tells the command to force-close any running applications, which prevents any errors or programs from unintentionally preventing our remote PC from executing the reboot command. Finally, the -t parameter instructs the command to perform the reboot with a zero-second (0) delay.
You can customize the shutdown command as you desire, such as having the command actually shut down the remote PC instead of rebooting it (-s instead of -r), add a time delay, display a custom message before shutting down, and more. You can also combine shutdown commands along with specific computer names or addresses to reboot or shut down multiple PCs at once.
save remote reboot batch file
When you’re done crafting your shutdown command, go to File > Save and navigate to a convenient location for your batch file. Next, select the Save as type drop-down menu and select All Files. Finally, give your batch file a name in the File name box, and end it with a .bat extension. In our example, we’ll name our batch file Remote Reboot.bat and place it on the desktop of our remote PC.
remote reboot batch file
You can now close Notepad and, if you’re ready, test the batch file by double-clicking on it to execute it. If the shutdown command was formatted correctly, you’ll see your remote PC reboot or shutdown with the designated parameters and options. Once you’ve verified that your batch file works as intended, you can duplicate and modify the command as needed for additional remote PCs.
Also note that we’re using a batch file to automate the shutdown command in the context of a remote PC, but this command and the batch file itself will work on any Windows PC on which it is executed (or any network PC designated by the -m parameter), including your local PC. This article also focused on executing the batch file via a remote desktop GUI, but you can also launch a batch file via the command line.

OS X El Capitan: How to Copy a File Path in Finder

Read Next 

2 thoughts on “Quickly Shut Down or Reboot a Remote PC with a Custom Batch File”

Chetan Borkar says:
But how the batch file knows about the remote pc which we want to reboot/shutdown .. kindly explain
James Way says:
Because this article is useless. The author is having you write the script store it on the target pc and run the bat file remotely on the pc so it can reboot itself. The privileges required to run a script remotely on the remote machine should grant you privileges to run “shutdown /r /m \servername” instead from another pc. That or if you want to execute the script remotely, you can use psexec, not the preferred method, or powershell remote sessioning.
Jeremy Molina says:
I dont know if is me, but the command itself works to shut-down/reboot local computer because you are running the command over the same computer, you must clear which is the full command and how to set-it up to makes a remote(Other computer connected to the same LAN) shut-down or reboot.
I copy from Microsoft Web-Site which is the full command you must set-it up to makes a remote, network connected computer shut-down:
Examples
To shut down \MyServer in 60 seconds, force running applications to close, restart the computer after shutdown, indicate a user code, indicate that the shutdown is planned, log major reason code 125, and log minor reason code 1, type:
shutdown -r -f -m \MyServer -t 60 -d up:125:1
Here is the source: https://technet.microsoft.com/en-us/library/bb491003.aspx?f=255&MSPPError=-2147217396

Leave a Reply

Your email address will not be published. Required fields are marked *


Jim Tanous

Dec 7, 2015

676 Articles Published

More