Reboot Remote PC Batch File: How to Restart Over Network
In this article
To reboot a remote PC with a batch file, you use the built-in Windows shutdown command with the /r flag and the /m parameter to specify the target computer’s name or IP address. For example, shutdown /r /m \\192.168.1.50 /t 0 will restart that machine immediately, provided your account has permission and the necessary firewall rules allow it. This article explains the exact syntax, how to set it up, common errors, and safer alternatives.
Why Use a Batch File to Reboot a Remote PC
Batch files are simple text scripts that run Windows commands in sequence. They are ideal for repetitive administrative tasks because they require no extra software, work on all modern Windows versions, and can be edited with Notepad. Rebooting a remote machine from your desk saves time compared to physically walking to the computer or using a remote desktop tool just to click Restart. It also allows you to script reboots for multiple machines at once by looping through a list of computer names.
The Core Command: shutdown /r /m
The shutdown.exe utility has been part of Windows for decades. The relevant switches are:
/r– full restart (as opposed to/sfor shutdown or/lfor logoff)/m \\computername– target the remote machine (use the computer’s name, IP address, or FQDN)/t xxx– delay in seconds before restart (0 means immediately)/c "message"– optional comment shown to the user/f– force close running applications without warning (use cautiously)
A basic batch file might look like this:
@echo off shutdown /r /m \\192.168.1.50 /t 0
If you want to give the user 30 seconds to save work, change /t 0 to /t 30. To restart several PCs, add multiple lines or use a for loop.
Prerequisites for Remote Shutdown to Work
Three things must be true for the command to succeed:
- Permissions: Your account must have administrator rights on the remote machine. In a domain environment, domain admins usually have this by default. In a workgroup, you may need to run the batch file as administrator and the remote machine must have the same local admin credentials.
- Firewall rules: Windows Firewall blocks the remote shutdown service by default. On the target PC, you must enable the “Remote Shutdown” rule (found under Windows Defender Firewall → Advanced Settings → Inbound Rules, or via the command
netsh advfirewall firewall set rule group="remote shutdown" new enable=yes). This opens TCP port 445 and UDP 137–138. - Network discovery: The computers must be able to resolve each other’s names. Using an IP address avoids DNS issues.
How to Write and Run the Batch File
Creating the file is straightforward:
- Open Notepad.
- Type the shutdown command(s) as shown above.
- Save the file with a
.batextension (e.g.,reboot-pc.bat). Choose “All Files” in the Save As type to avoid getting a.txtfile. - Run the file by double-clicking it, or from an elevated Command Prompt if you need admin rights.
To avoid the window closing before you see an error, add pause at the end. For a more informative script, you can add a check for the exit code:
@echo off shutdown /r /m \\192.168.1.50 /t 0 if %errorlevel%==0 (echo Restart command sent successfully.) else (echo Failed with error %errorlevel%.)
Common Problems and How to Fix Them
If you get “Access denied (5)” or “The network path was not found (53)”, check these in order:
- Is the remote PC on and reachable? Try
ping 192.168.1.50. - Are you using the correct name/IP? Use
ipconfigon the remote machine to confirm. - Is the firewall rule enabled? Re-run the netsh command above.
- Are you running the batch file as an administrator? Right-click and choose “Run as administrator”.
- Is the target in a workgroup? You may need to create matching local accounts with the same password on both machines.
Another issue: if the remote PC is a laptop that sleeps, it won’t respond. Wake-on-LAN is a separate feature that can power it on, but it cannot wake a sleeping machine with a shutdown command.
Alternatives to a Batch File
While a batch file is the lightest solution, other methods exist:
- PowerShell:
Restart-Computer -ComputerName 192.168.1.50 -Forcegives more control and can handle multiple machines with a single command. - PsExec: Part of Sysinternals, it can run the shutdown command remotely and bypass some firewall issues if configured.
- Remote Desktop / SSH: Log in and restart manually, or run
shutdownfrom the remote session. - Group Policy / MDM: For large fleets, a central management tool can schedule restarts.
Safety and Best Practices
Always use the /t parameter with a delay (e.g., 30–60 seconds) so users can save work. The /f flag forces close applications and can cause data loss; use it only when necessary. Also, test the script on a non-critical machine first. Document the script’s purpose in a comment line (REM) so future admins understand it. Finally, remember that the command works only within the same network or VPN; it will not work over the public internet unless you set up port forwarding, which is not recommended for security reasons.
Frequently Asked Questions
Can I reboot a remote PC without admin rights?
No. The shutdown command requires administrative privileges on the target machine. Without them, you will get an “Access denied” error. You can ask the user to run the command themselves or provide you with admin credentials.
Why does the batch file work for one PC but not another?
Usually it’s a firewall rule difference or a permissions mismatch. The target PC may have a different local account password, or the firewall rule was not enabled on that machine. Verify each prerequisite individually.
Can I schedule a remote reboot with a batch file?
Yes. You can combine the batch file with Windows Task Scheduler on your local machine. Create a task that runs the batch file at a specific time. The remote PC must be on and reachable at that moment.
Is there a way to reboot multiple PCs at once?
Yes. Use a for loop in your batch file, for example: for %%i in (pc1 pc2 pc3) do shutdown /r /m \\%%i /t 0. Or list the names in a text file and use for /f %%i in (computers.txt) do shutdown /r /m \\%%i /t 0.
What if the remote PC is a Linux machine?
The shutdown command is Windows-specific. For Linux, you can use SSH to run sudo reboot. From Windows, you can use PuTTY’s plink tool or PowerShell’s SSH module, but that requires SSH setup on the Linux machine.
Does this work on Windows 11 and Windows 10?
Yes. The shutdown command is unchanged in both versions. The firewall rule name is also the same.