Introduction.
Sometimes it is useful to remotely restart a windows based machine without having access to a remote session. This recently happened to me on a server (in a different country) which I had asked to restart from a VNC session. For some reason, some of the applications didn't close when asked to by Windows and the server sat there, waiting. VNC server was one of the applications which had closed when asked, and RDP was disabled (for other reasons) so I could no longer access the machine. No-one was at the location of the server, so I needed a way of restarting it from my desk, and quickly!
Guide.
From another Windows machine which has network access to the machine you wish to restart/shutdown, follow the following:
- Open a "Command Prompt" window (WIN + R ->
cmd
) - Type the following
shutdown -r -m \\HOSTNAME -c "Restarting for maintenance" -t 5 -f
and press enter-r
is to restart the machine. Replace with -s to shutdown instead-m \\HOSTNAME
is to specify the computer you wish to restart/shutdown. Omitting this will make the command work on your local machine. Replace HOSTNAME with the hostname of the remote computer (if your local machine can resolve it) or the remote computers IP address.-c "Reason why you are shutting down/restarting"
is to specify a comment, which will be written to the logs. You can omit this if desired.-t 5
is the number of seconds until the action will take place. It will give anyone else using the machine some warning before the machine shuts down or restarts. You can lower this down to 0 (or any other value) if desired.-f
forces the remote machine to perform the action. This was useful in my case where the machine was already doing a non-forceful reboot, but was waiting on applications to close. This option can be omitted if you want a more graceful shutdown.
- If you receive a "permission denied" error to the above command, you will have to authenticate with the remote machine, and then issue the shutdown command again:
- To authenticate with the remote machine, type the following command:
net use \\HOSTNAME /user:DOMAIN\USERNAME PASSWORD
- Replace HOSTNAME with the remote machines hostname or IP address
- Replace DOMAIN with the domain of the machine. If the machine is not on a domain, omit this, and the trailing backward slash
- Replace USERNAME and PASSWORD with the username and the password of a user with permissions to shutdown/restart the remote machine
- Providing the above command returns
The command completed successfully.
, rerun theshutdown
command, which should run successfully this time.