How to start VirtualBox machines automatically as a service

You might be familiar with VirtualBox, a free and open-source software package for running virtual PCs on a host machine. It was developed by Oracle and can be installed on Windows, Macintosh, Linux, and Solaris hosts.

Supported guest operating systems, those running virtually inside the “box,” include DOS, just about every Windows version since NT 4.0, major Linux kernel versions, Solaris, and OpenSolaris, OS/2, and OpenBSD. Others probably work too. Setting up VirtualBox 5.0 is a fairly simple process, and is largely unchanged from earlier versions that have been covered here before.

There remains one glaring omission in this otherwise excellent Hypervisor product, however. To spot it, just check chapter 9, section 24 of its online manual:

Starting with VirtualBox 4.2.0 it is possible to start VMs automatically during system boot on Linux, Solaris and Mac OS X for all users.

That’s right, there’s no option to automatically launch your virtual machines on a Windows host. Server reboots? Sorry, your virtual machines are still turned off. Better go log in and boot them all up again.

Luckily, there are a couple third-party solutions to this problem. This article will cover VBoxVmService, a trusty helper I’ve used for the past couple years in a live Windows server environment.

Configure your virtual machines

Before doing anything with VBoxVmService, set up all your virtual machines the way you like them. Oracle’s VirtualBox Manual has pretty good instructions (if distressingly few screenshots). Modifying any one VM after VBoxVmService is running is a tiny bit of a hassle, so choose settings that won’t need to be changed often.

All set? Okay then.

Download & Install VBoxVmService

Head on over to VBoxVmService’s Sourceforge page and click the main image to download the EXE installer. Run the executable for a very standard wizard, which places all its files in C:\vms by default. Head to that directory to find a nice little list of files.

vboxvmservice-files

We’re mostly concerned with the INI file, since that’s where all our settings go. Open it up in Notepad or your preferred text editor to see its initial state.


[Settings]
VBOX_USER_HOME=C:\Users\John\.VirtualBox
RunWebService=no
PauseShutdown=5000

[Vm0]
VmName=ubuntu
ShutdownMethod=savestate
AutoStart=yes

[Vm1]
VmName=winxp
ShutdownMethod=savestate
AutoStart=no

Configure the INI

The VBOX_USER_HOME variable is probably fine as-is if you installed VirtualBox and VBoxVmService with their default settings. The path is not the same (necessarily) as the Default Machine Folder set within the Preferences of Oracle VM VirtualBox Manager.

RunWebService controls whether or not to start VirtualBox’s HTTP web service automatically, so only change that to “yes” if you need it. PauseShutdown allows extra time, in milliseconds, for VMs to gracefully shut down if the host machine is shut down.

  • You will have to pay attention to the rest. [Vm0] and [Vm1] show sample values for:
  • the name of each of your VMs (VmName)
  • how VMs should react when told to stop (ShutdownMethod, either “savestate” for a quick session snapshot or “acpipowerbutton” for a full shutdown), and
    whether or not to boot when VBoxVmService starts (AutoStart)

The first thing to do is to replace the VmName with the name of your VM(s). If you only have one, remove everything from [Vm1] on. If you have more than two, add more sections with the same format starting with [Vm2], then [Vm3], etc.

Depending on your user permissions, you might also need to add two lines granting the service access to the VBOX_USER_HOME directory. Put them in the [Settings] section:


RunAsUser=.\yourusername
UserPassword=yourpassword

Don’t worry, that cleartext password is only there very briefly. You can delete those lines immediately after installing the service.

Save VBoxVmService.ini and then open a command prompt as Administrator. Run the following command, which installs the service:

C:\vms\VmServiceControl.exe -i

You might get an error message:

Failed to create service VBoxVmService: The specified service already exists.

If so, just uninstall and reinstall the service:

C:\vms\VmServiceControl.exe -u
C:\vms\VmServiceControl.exe -i

In fact, any time you change something in VBoxVmService.ini, you’ll need to uninstall and reinstall the service. Adding or removing a VM, altering a VM’s AutoStart or ShutdownMethod, or tweaking the PauseShutdown time will require this procedure.

It’s not a bad idea to reboot either.

Control the VirtualBox service

Back in the C:\vms folder, open VmServiceTray.exe to get a handy little icon near your clock that allows you to start and stop VBoxVmService, as well as any individual VMs. Create a shortcut and place it in the Startup folder to always have it on hand at boot.

stop-vmboxvmservice

You should be able to open the VirtualBox GUI with the service and VMs still running, but that wasn’t always the case. Versions 4.2 and 4.3 of the GUI wouldn’t open while VBoxVmService was started, so to make any modifications or add new VMs, the service (and therefore all running VMs) had to be stopped. If that issue pops up for you in version 5, take the following steps before opening the GUI:

  1. Right-click the System Tray icon.
  2. Go to each VM listed and select “Stop”.
  3. After stopping each VM, select “Stop VBoxVmService”.
  4. Wait about 10 seconds and open the Oracle VM VirtualBox GUI.

You can now make changes to the VMs and open them interactively. When you’re done, close the VMs, close the VirtualBox GUI, and restart the service and each VM via the System Tray icon. Again, this shouldn’t be necessary with version 5, but it can’t hurt to be prepared.

Access your virtual machines

Once started through VBoxVmService, your virtual machines can be used like any other remote machine – via Remote Desktop, VNC software, LogMeIn, TeamViewer, or whatever your preferred solution is.

Even though the Oracle VM VirtualBox Manager can be opened while your VMs are running under VBoxVmService, their state won’t be correctly reflected in that GUI. Try to start one that says it’s powered off and you’ll get a nasty error box containing multiple failures. You can stop the relevant VM through the System Tray icon if “ShutdownMethod” in your VBoxVmService.ini file is set to “acpipowerbutton”; if it’s “savestate”, though, you’re better off remoting into the VM and shutting it down properly.

virtualbox-error

For advice and hacks related to earlier versions, the VBoxVmService wiki is a good place to start. Happy virtualizing, and let us know your experiences!

About The Author

8 thoughts on “How to start VirtualBox machines automatically as a service”

  1. @john
    Thanks for covering our project in such great detail. When I started VBoxVmService some years back, I had no idea it would still be around and thriving today. 🙂 Even though I turned over the development to Zhe, aka flybird2k some time ago, I google the project from time to time to see what’s up with it.
    The problem with running the GUI parallel to the service has been quite a turbulent history. With the current VirtualBox 5.x it has gotten a little better in terms of coexistence. Anyone interested should read this article in the Wiki:
    https://sourceforge.net/p/vboxvmservice/wiki/Runing%20VirtualBox%20GUI%20together%20with%20VBoxVmService/

    @viral
    There have always been other possible solutions to start the VMs at boot time but VBoxVmService is the only one (to my knowledge) that gracefully shuts down or saves the state of your VMs at the host’s shutdown or reboot. Any other solution basically just pulls the plug on your VMs.

  2. I tried to follow that guide but I can’t get the service to start in Windows 10. I keep getting the following error message:

    “The VBoxVmService service is marked as an interactive service. However, the system is configured to not allow interactive services. This service may not function properly.”

    What do I have to change to get the service to start?

  3. David McClanahan

    Please, if you don’t mind, Oracle did not do the original development, they got it along with Sun when they bought Sun in 2010 who bought it from a German company Innotek in 2008. Let’s please not give Oracle more credit than they deserves, they are already one of the most arrogant companies in the world!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top