Virtualbox Windows graceful shutdown of guests on host shutdown

I am trying to find a solution to gracefully shutdown any guest VMs running under VirtualBox Windows when the host computer is shut down or restarted.

It seems that the safest option would be to trigger the "save state" command when the host starts shutting down, but it is not clear whether the host will wait long enough for the VMs to finish saving state and power off.

Does anyone have a robust solution for this (seemingly basic) issue?


Solution 1:

Sorry I'm late to the party. There is an exact answer to this, though it requires some commandline-foo. See this thread post for more information: https://forums.virtualbox.org/viewtopic.php?f=6&t=53684#p285540

The command you are looking for is:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" setextradata "VM NAME" GUI/DefaultCloseAction Shutdown

This is what I use on multiple VMs, close the window and it starts a safe shutdown automatically. Shutdown Windows, and in its attempt to close everything, it will wait for these processes to complete.

Solution 2:

I had a similar problem and solved it by running VirtualBox as a service:

https://github.com/onlyfang/VBoxVmService

With VBoxVMService you can chose how you want the machine to shutdown (Save state, power off) and startup. Since it's running as a service, Windows will automatically wait for it to shutdown, during the system shutdown process.