Automatically reboot virtual machines

Steven GraffOwner
CERTIFIED EXPERT
GoldMine Software installation, training, data migration, all things tech. GoldSMS, real-time texting from within GoldMine.
Published:
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
5,668 Views
Steven GraffOwner
CERTIFIED EXPERT
GoldMine Software installation, training, data migration, all things tech. GoldSMS, real-time texting from within GoldMine.

Comments (1)

CERTIFIED EXPERT
Author of the Year 2009

Commented:
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.

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.

Get access with a 7-day free trial.
You Belong in the World's Smartest IT Community