[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


Automatically reboot virtual machines

Published on
11,398 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 50

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

Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Join & Write a Comment

This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Other articles by this author

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month