Automatically reboot virtual machines

Published on
11,281 Points
Last Modified:
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.
1 Comment
LVL 49

Expert Comment

Not all Windows systems include the tsshutdn executable.  I couldn't find it on my Win7 system, but I found an alternative, the PsShutdown utility, from SysInternals.  Some related options are listed here.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Join & Write a Comment

This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Other articles by this author

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month