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
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.
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.
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.
Want news and tips from TekRevue delivered directly to your inbox? Sign up for the TekRevue Weekly Digest using the box below. Get tips, reviews, news, and giveaways reserved exclusively for subscribers.