WinOS – Restart Computer through Script

Background

Needing to restart a computer that is not accessible via Remote Desktop.

Script

DOS Batch

Here is a Dos Script that can help.

Outline

  1. Expects lone argument passed in to be computer name of host to restart
  2. Initiates shutdown.exe
    • /r :- Restart
    • /d p:0:0 :- Reason is a planned restart
    • /m :- Computer that is target of restart
    • /c :- Reason
      • User that initiated restart and host restarted from

Code


@echo on

setlocal

rem /r
rem restart computer

rem /d 
rem   p = planned restart

if [%1]==[] (
	echo Please pass along computer name as first parameter
	echo Exiting Script
	goto :endofScript
	)

set "_usernamefull=%USERDOMAIN%\%USERNAME%"

set "_computer=%1"

set "_reason=Planned restart by %_usernamefull% from host %COMPUTERNAME%"

shutdown.exe /r /d p:0:0 /m \\%_computer% /c "%_reason%"

:endofScript

endlocal

Output

Output #1

Image

Textual

LABDB: The entered computer name is not valid or remote shutdown is not supported on the target computer. Check the name and then try again or contact your system administrator.(53)

Output #2

Image

Textual

You're about to be signed out
Windows will shut down in less than a minute.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s