Shutdown VirtualBox VMs when PC shutdown

Soldato
Joined
28 May 2010
Posts
4,800
Location
London, UK
Hi
I have a PC with 2 x Oracle VirtualBox VMs running for testing purposes(for now).
I have setup a .bat file with the following command;

========================================
cd "C:\Program Files\Oracle\VirtualBox\"
VBoxManage.exe startvm "VM1"
VBoxManage.exe startvm "VM2"

========================================

Then I have setup a task in windows task scheduler to auto execute the above .bat file upon system startup.

I know the command to shut down the VMs,

==========================================
cd "C:\Program Files\Oracle\VirtualBox\"
VBoxManage.exe controlvm "VM1" acpipowerbutton
VBoxManage.exe controlvm "VM2" acpipowerbutton

===========================================

But what I can not figure out is how to create a task to execute on system shutdown(and restarts)!

TLDR:
Want to automatically start and shutdown VMs on PCs start and shutdown(and restart) events.


Any ideas?
 
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm VMNAME1 savestate
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm VMNAME2 savestate
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "VMNAME 3" savestate
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm VMNAME4 savestate
shutdown /p /f


That saves them instead of shutting them down, this starts them..

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm VMNAME1

As said in the op, I have managed to put the startvm command to a batch file and set it to run on host PC's startup event from task scheduler.

How do I get the savestate to happen when the Host PC is shutting down or restarting?
 
Ahhh ok...I didn't see the last part of your post when I replied! :)

I may have to use your solution until I find a better one - Thank you!
I was thinking of leaving the Host PC to fully automate everything and leave it as a headless host VM box!
But when the windows updates run and requires a restart it created a problem for the VMs - that's the reason for trying to automate the shutdowns for VMs on Host shutdown/restart event.
 
Back
Top Bottom