Restart Windows 2008 automatically with a batch (bat) file

This is not difficult to perform and can be used for Windows Servers 2003 and 2008. A reason for performing this type of restart would be to restart the server on the weekend when no one is working. Be warned: Unassisted server restarts can experience undocumented features that may facilitate the necessity to return to work during your time off.

The basic command is: shutdown

The flag for restart is: /r

Now, if you have a “reason” screen you will need to add the reason. If the restart is planned you will use: p if the restart is unplanned you will use: u. To find a listing of the reasons for the restart open a command window and type: shutdown /?.

Here is an example: shutdown /r  /d p:4:1

Now let’s do this step-by-step.

Create the BAT file. Log into the server with Admnistrator rights and privelages. Open Windows explorer and right click on the directory you would like to create the .bat file and create a new text file. I will call this file restart_server.bat.


Notice the file is still type “Text Document?” In order to change that go to: Organize -> Folder and Search Options

Select the View tab and unselect the Hide extensions for known file types. Then press OK.

Rename the restart_server.bat.txt to just restart_server.bat. You will receive a warning message about the dangers of changing file extensions. Just click OK.

Right click on restart_server.bat and select edit.

Add the script shown above to the file and save the file. Be very careful here, because you now have a batch file that will restart the server if it is run.

Now to add the batch file to Task Manager.

Open Task Scheduler and select Create Basic Task…

On the first screen give the task a name and description. You must give it a name. I would recommend giving it a description as well, becuase you might not remember what it was 1 month or 1 year from now. Then click Next.

On the Trigger screen select when you would like the restart to run. I selected weekly for this example. Click Next

Select the day and time you want the task to run. I selected Saturday and 8:30:33 PM. Click Next.

On the Action screen ensure Start a program is selected. Click Next.

On the Start a script section browse to the batch file you just created. Click Next.

The Finish section will provide a summary of the task just created. Click Finish

The task is now schedule to run on Saturday night at 8:30:33 PM. Now comes the task of letting all users know that the server will restart every Saturday night.

While in Task Scheduler you can also highlight the job by selecting it and click Export to export it as an XML file. You can copy the XML file to other servers, open Task Scheduler and click Import to set up the job. You might need to schedule the Run as use.

To remove the task, click on the Task Scheduler Library. Highlight the task and delete it. Also remember to remove the batch file, because you do not want someone to run it.


Comments are closed.