63

In 2013 I tracked down how to autostart/shutdown a Virtualbox VM when the host is Linux. The process was officially documented and required a few steps.

Right now I am interested in, how do you configure Virtualbox VM to autostart after Windows reboot?

Is there an officially documented process? If not, what are some person's tested solutions?

My naive attempt was going to be something like:

  • done: Setup windows to auto-login upon reboot

  • TODO: Create batch script with: sleep 120 && vboxmanage startvm my_vm_name

  • TODO: Put the batch script into my user's startup directory. (I didn't see any "startup" directory in windows 10 though...)

9 Answers9

45

The start up directory does still exist, albeit in a well hidden place...

Access it via opening the "Run" box (Win+R) and entering

shell:startup

Minimise this for now.

Open VirtualBox and right click on the VM you want to autostart, click the option to create a shortcut on the desktop and close VirtualBox.

Simply cut the shortcut from the desktop and paste it into the previously opened folder and it should be perfectly fine.

Unencoded
  • 3,528
21

You can actually start a VM headlessly without resorting to a third-party VBoxVmService now. Just create a shortcut to <VirtualBoxDirectory\VBoxManage.exe> startvm "vmname" --type headless and put that in your startup folder.

From the VirtualBox manual.

Chad
  • 311
21

The truly most-consistent option is to use Task Scheduler.

Implementing the solution

This requires a couple of pretty easy steps, but I will explain them in detail to ensure anyone from any technical background can set this up:

  1. Identify your virtual machine name
  2. Create a task in Task Scheduler

1. Identify your virtual machine name

Navigate to C:\Users\YourUserNameHere\VirtualBox VMs

VirtualBox VMs Folder

The folder name above generally reflects the virtual machine name. You can confirm this by checking VirtualBox Manager itself:

VirtualBox GUI

The machine name is WindowsXPSP3.

2. Create a task in Task Scheduler

First click the start button and type "task scheduler" without the quotes. Then open the Task Scheduler:

Task Scheduler Search

Inside the task scheduler, we're going to see a structure tree on the left side. Right-click on Task Scheduler Library. Left-click on New Folder...:

Task Scheduler New Folder

Name the folder something memorable, like User Custom and hit OK (if you already have an existing folder that you would prefer to use, that's fine as well, skip to the next paragraph instead):

Name New Folder

Click your newly created folder, in my case User Custom, to highlight it. Right-click in the empty list to the right and Left-click on Create New Task...:

Create New Task

Now comes the tricky stuff. Follow my instructions verbatim. If you feel like downvoting because it didn't work, or say "this didn't work for me" in the comments, I'm betting you skipped a step here. Come back and try it again.

The Name and Description can be whatever you like, it is merely aesthetic and will not affect functionality. I'm going to name mine after my virtual machine and put a brief description. What IS important is that you choose Run whether user is logged on or not and Run with highest privileges:

Create Task: General

Switch to the Triggers tab at the top and Left-click New.... Switch the Begin the task: combination box to At Startup and then Left-click OK:

New Trigger

Switch to the Actions tab at the top and Left-click New.... Click browse (do not try to type this manually, you will cause yourself headaches) and navigate to C:\Program Files\Oracle\VirtualBox. Highlight VBoxManage.exe and Left-click Open:

Browse to VBoxManage

Copy everything except the executable and the quotation marks from Program/script: into Start in (optional)::

Copy Directory Path

Finally, put the following line into Add arguments (optional): and hit OK:

startvm "YourVirtualMachineNameFromStep1" --type headless

in my case, I will use:

startvm "WindowsXPSP3" --type headless

Enter Arguments

My Conditions tab is generally set to the following:

Conditions Tab

Make sure your Settings tab looks like the following, but absolutely ensure you have set the items marked in yellow to match mine. This will make sure that if some pre-requisite wasn't ready yet that it will retry a few times to start the virtual machine and that the virtual machine won't be terminated after 3 days. I would leave everything else as default unless you know what you are doing. If you don't do what I show you here, and it ends up not working, it's your problem:

Settings Tab

Finally, hit OK at the bottom of the Create Task window. You are done!

Testing the solution

Testing My Fake Scenario Above (and how you can test yours)

When I restart my computer, I can log in and open the VirtualBox Manager and see that my VM is running:

Running VM

I can also open Task Scheduler back up, and verify that it ran successfully, or see what the error was if it did not (most errors will be directory errors from people trying to manually enter where I told them not to):

Task Scheduler Success

Testing My Actual Use Case

On another machine, I set up my Linux Server as a virtual machine with it's own raw solid-state hard drive. I wanted that Server to boot back up if the machine got restarted (crash, windows update, etc) automatically, without the user having to log in. I set that one up exactly as I described above and restarted that machine. I know it worked successfully because I was able to access my Samba share (laymens: a folder with stuff in it that I share over my network to my other computers) from another computer WITHOUT having first logged into the machine that runs the Server VM. This 100% confirms that it does start on system boot and not after the user logs in.

DeeJayh
  • 406
12

Try VBoxVmService

Make sure to read the Howto.txt and edit VBoxVmService.ini

AKi
  • 228
  • 1
  • 4
  • 8
10

While having a Service is nice, you can do it with a scheduled task. Take system boot as the trigger, check the option to run the task without a logged-on user and set the action to <VirtualBoxDirectory\VBoxManage.exe> startvm "vmname" --type headless. Make sure to remove the check from the incomprehensibly default-on option "kill the task if running for more than 3 days". Srsly, MS, what were you thinking, that no Windows computer would ever last that long without reboot?

There is a caveat: if a VM is started on boot that way, you will see it in the VirtualBox Manager as "powered off", so there's no button to show the display of the VM. There's only the "start" button and you will probably screw things up when you try to double-start it.

You can define a remote display port so that you can access the console of the VM thru RDC (mstsc.exe), without the VirtualBox Manager, but you still have to remember to not believe the "powered off" information. I don't know if that works better with a real service.

gonesoft
  • 101
5

Try VBoxHeadlessTray.
It's really easy to use, which automatically restore VM's state when Windows boot up and save state when Windows shutdown or restart. What the most awesome is you can use VBoxHeadlessTray to configure each one of your VMs.

3

As previously stated by chad and gonesoft, you can use VboxManage.exe to start the VM on launch, however, if you do not specify "--type headless" it will actually show up in the VirtualBox Manager as running etc. just like as if you had started it normally, headless is what makes it hidden - not something you'd likely want to do in all cases...

Posting as answer as i don't have enough reputation to write a comment to the previous answers

Swizzy
  • 31
0

Try VboxTrayCom

This program allows you to start virtual machines, shut them down correctly, and it does not have configuration files.

0

After trying several solutions (see bottom), I resorted to creating a shortcut to a PowerShell script, to start my VM in headless mode, so it doesn't take up space on the taskbar, a must for me.

Here's the script (named, for example startvm.ps1):

cd 'C:\Program Files\Oracle\VirtualBox\'
.\VBoxManage.exe startvm "VirtualMachineNameOrUUID" --type headless

The shortcut, placed under C:\Users\yourusername\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup, which can be conveniently accessed through WIN + R and running shell:startup, has something like:

Target: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "C:\Users\yourusername\scripts\startvm.ps1"

Start in: C:\Users\yourusername\scripts

I can see the powershell Window pop up after login and it goes away within seconds. However, because I have placed a CPU execution cap, it can take a long time for the machine to become available during a heavy startup with lots of applications eating up the CPU cycles and putting the fans in helicopter mode. It may be necessary to use the VirtualBox UI to give it priority by clicking "Show", or just restart the machine again to shut up the fans as well!

Other Things I Tried Which Did Not Succeed

  1. Created a shortcut in Startup to directly run VBoxManage.exe startvm "VMname" --type headless by editing the shortcut added by the VirtualBox UI. The original shortcut works when I double-click it, but not the edited one.

  2. Followed a related answer to launch it before login by placing the PowerShell script under C:\Windows\System32\GroupPolicy\Machine\Scripts\Startup (had to create Scripts\Startup). I probably need to return to this when I have more time, and find a solution that works without messing around with the global execution policy.

  3. Since the default shortcut (created by the VirtualBox UI) uses VirtualBoxVm.exe I did .\VirtualBoxVm.exe --help to see if there was a headless option. I saw seamless and tried it but it's not the same as headless.

  4. Ran the VBoxHeadless.exe instead but it opens up a terminal Window that I could not close without stopping the VM, defeating its purpose, so it didn't bother trying a shortcut with it.

  5. Ran .\VBoxManage.exe modifyvm "{my-vm-UUID}" --defaultfrontend headless, then placed the default shortcut on the Startup folder.

It is possible that I missed something and one of these options might work for you.

Nagev
  • 981