How do you configure Virtualbox VM to autostart after Windows-10 reboot?
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-10 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...)
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 with any technical background can set this up:
- Identify your virtual machine name
- Create a task in Task Scheduler
1. Identify your virtual machine name
Navigate to C:\Users\YourUserNameHere\VirtualBox VMs
The folder name above generally reflects the virtual machine name. You can confirm this by checking VirtualBox Manager itself:
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:
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...
:
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):
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...
:
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
:
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:
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
:
Copy everything except the executable and the quotation marks from Program/script:
into Start in (optional):
:
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
My Conditions
tab is generally set to the following:
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:
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:
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):
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.
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.
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.
Try VBoxVmService
Make sure to read the Howto.txt and edit VBoxVmService.ini
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.