52

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...)

4
  • i wasn't sure about using the startup menu... because it is very windows-9x-ish (maybe it's older). In linux I used sysvinit/systemd but I'm just not familiar with Windows (maybe task-scheduler or some such). Jan 17, 2016 at 2:46
  • Could be useful if you add a link to The process was officially documented on linux ;-) Oct 3, 2018 at 11:17
  • @PhilippeGachoud as per your request, i edited the question and added a link to the documentation Oct 3, 2018 at 17:24
  • Thx! I found this more adequate because less sensible to changes of packages managment configuration as seems to be the case, whats your experience with that? medium.com/@bharatman/… Oct 3, 2018 at 17:56

9 Answers 9

9

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:

  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.

4
  • You can simply change the Begin the task: to At logon instead of At Startup and Run only when user is logged on instead of Run whether the user is logged on or not, if you desire it to occur ONLY AFTER the user logs into the system.
    – DeeJayh
    Apr 28, 2021 at 18:17
  • 1
    oh my goodness. your answer is truly amazing. great writing. great screenshots. and even testing it with screenshots to show testing. above and beyond. i left it unsolved for years. but you sir get the green checkmark. Apr 28, 2021 at 18:31
  • @TrevorBoydSmith thank you very much. This too has plagued me for some time. Now that I looked into it again and saw that they implemented the startvm "name" --type headless I knew it was finally attainable... I have posted it on other similar windows-vm-on-boot type questions as well so that hopefully many can enjoy this feature.
    – DeeJayh
    Apr 28, 2021 at 18:39
  • Please do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by voting to close it as a duplicate or, if you don't have enough reputation for that, raise a flag to indicate that it's a duplicate. Otherwise tailor your answer to this question and don't just paste the same answer in multiple places.
    – DavidPostill
    Apr 28, 2021 at 18:59
42

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.

4
  • 4
    shell:startup is on login, not on system boot, correct? How to do this on system boot?
    – alexei
    Jan 1, 2017 at 17:00
  • 1
    You need to run it as a service
    – AKi
    Jan 26, 2017 at 19:33
  • 1
    Not necessarily. You can always configure autologon, Open a cmd and type control userpasswords2. You'll find your way through the rest.
    – drakorg
    Oct 26, 2018 at 4:48
  • While this does work after the user logs in, it will not work BEFORE the user logs in (on reboot, as the question asked). For a proper solution, see this answer: superuser.com/a/1645276/524595
    – DeeJayh
    Apr 28, 2021 at 18:31
20

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.

4
  • 6
    Doesn't this still have the disadvantage of requiring login instead of just running on boot?
    – HorusKol
    May 20, 2017 at 1:34
  • Of course. A service is still a necessity if you want to run anything without having to log in.
    – rustyx
    Sep 5, 2017 at 12:12
  • 5
    Use a Scheduled Task for that instead of shortcut in the startup folder. Jun 14, 2018 at 12:52
  • @HorusKol that is correct. Bruno Finger has the right idea. The proper solution is available here: superuser.com/a/1645276/524595
    – DeeJayh
    Apr 28, 2021 at 18:32
12

Try VBoxVmService

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

6
  • 1
    Thank you so much! this looks very promising. On Windows, the lack of Virtualbox integration with system start/shutdown was always a big negative when you wanted to compare windows-virtualbox vs linux-virtualbox (even tho the linux virtualbox integration is only sysvinit... and is IMO not very robust (shutdown of VMs does not wait for the VM to shutdown before system issues SIGKILL and then does system shutdown)). May 20, 2016 at 15:50
  • 1
    I tried this about a year ago. This solution requires that you update virtualbox in lockstep with the wrapper code that does the windows service. And so you have to be careful. Also a windows update i think broke this functionality for me. And so i ended up uninstalling this vbox-service code. Jul 26, 2017 at 13:04
  • I looked at this project. The sheer volume of spelling mistakes makes me worry about similar issues in the code. Mineshaft+canary. Sep 13, 2018 at 15:45
  • @user2066657 well you can read my comments and see that I tried it and it worked for a little bit then got broken. your concerns about spelling mistakes indicating the quality of code is probably well founded. i still would not go back to it today. Oct 3, 2018 at 17:34
  • The link is broken. I wonder if this is the same project: github.com/onlyfang/VBoxVmService
    – Wtower
    Apr 13, 2020 at 13:07
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.

7
  • 1
    re "having a Service is nice". unfortunately the VirtualBox service gets broken everytime there is a minor virtualbox update. so i ended up uninstalling the service and right now my VM does not start at boot anymore. Mar 17, 2018 at 17:53
  • re "[the VM shows up as] powered off [in VirtualBox Manager]" i believe this is caused by the way you are starting the VM. i suspect you are starting the VM as the root user. if you were to try and start the VM with a "runas" your user... your VirtualBox manager might work. Mar 17, 2018 at 17:57
  • 1
    now that i think of it... the VirtualBox service... ALSO shows up as "powered off" when you start it via the service. Mar 17, 2018 at 17:58
  • 1
    This looks very promising, but I can't get it to work... I created the job, with two commands -- to start my too "main" VMs. I see it in scheduler. I can click on it a pick "Run" -- the state changes from "Ready" to "Running", but the VMs do not start. Nor do they start upon boot... There must be something else to it...
    – Mikhail T.
    Aug 1, 2018 at 20:10
  • 1
    IT WORKS, tested on Windows 10 + Virtualbox 6.0.2. Recipe: Windows-key, type SCHED and launch task scheduler, Create Basic Task, Trigger: When the computer starts, Action: Start a program, Program (browse to VBoxManage.exe), arguments: startvm "vmname" --type headless, tick "Open the properties dialog for this task.. and finish, tick Run whether user is logged on or not, perhaps remove Conditions/Start only if the computer is on AC power, and Settings/Stop the task if it runs longer than.. (though really that one does not matter here since the launch is fast).
    – fgrieu
    Jan 18, 2019 at 8:25
4

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.

2
  • that looks amazing. i'll have to try it out when i have time. thanks. Jul 26, 2019 at 14:32
  • Works perfectly. Great late answer!
    – FloPinguin
    Jan 15, 2020 at 20:17
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

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\Public\Scripts\startvm.ps1"

Start in: C:\Users\Public\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.

2
  • Task scheduler was not used in this example.
    – Nagev
    Feb 27 at 16:44
  • My word, I have no idea why I thought that! Deleted.
    – Andy Gee
    Feb 28 at 15:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.