<

Automatically reboot virtual machines

Published on
11,484 Points
5,484 Views
Last Modified:
Approved
For a variety of reasons, it sometimes makes sense to reboot a Windows-based computer on a regular, perhaps daily basis. This "cures" a lot of ills by resetting processes, flushing caches, refreshing memory, and reestablish network connections. In a perfect world this would never be necessary, but the reality is, rebooting is frequently the easiest, best brute force, blunt instrument method of fixing what ails ya.

I recently tried (and, initially, failed) to set up automatic rebooting for a couple of my Virtual Machines. One is running Windows XP in a Virtual Server 7 environment, the other is running Windows Server 2003 in a Hyper-V environment. I tried using the ShutDown.Exe command
    shutdown /r /f
command in a Scheduled Task. Alas, that worked only when logged on to the machine interactively, but not otherwise. Task Scheduler indicated an exit code of 0x15.

I tested this extensively, using various permutations of user accounts, permissions, rights, etc. I tried moving a copy of the shutdown.exe file to the root of the c drive. Absolutely nothing worked!

Through extensive searching, I came across a suggestion (in another context) to use Tsshutdn.Exe, which is the equivalent command for restarting a Terminal Server.

It works!  I'm now successfully using...
c:\windows\system32\tsshutdn.exe 5 /reboot /d:5 /v

Open in new window

...as the command in my scheduled task.

All the options for the TSSHUTDN command are documented by opening a command window and typing tsshutdn /?; it shows:

TSSHUTDN [wait_time] [/SERVER:servername] [/REBOOT] [/POWERDOWN] [/DELAY:logoffdelay] [/v]

  /v                                 Display information about actions being performed.
  wait_time                  Seconds to wait after user notification before terminating all user sessions (default is 60).
  /SERVER:servername  The server to shut down (default is current).
  /REBOOT                   Reboot the server after user sessions are terminated.
  /POWERDOWN        The server will prepare for powering off.
  /DELAY:logoffdelay  Seconds to wait after logging off all connected sessions (default is 30).

Apparently, when using a virtual machine, the technology used to connect to its console is the equavelent of Terminal Server, or RDP.
0
Author:stevengraff
Enjoy this complimentary article view.

Get unlimited access to our entire library of technical procedures, guides, and tutorials written by certified industry professionals.

Get 7 days free
Click here to view the full article

Using this article for work? Experts Exchange can benefit your whole team.

Learn More
COLLABORATE WITH CERTIFIED PROFESSIONALS
Experts Exchange is a tech solutions provider where users receive personalized tech help from vetted certified professionals. These industry professionals also write and publish relevant articles on our site.
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Learn from the best.