Reputation: 3756
I am running VirtualBox in Windows Server 2016. I want to start both VirtualBox and a VM within that when Windows boots. I have seen some posts about starting VirtualBox on Windows boot, but I have not gotten that to work. And even if I did, that would not autostart the VM. I feel there must be a way to do this, but hours of googling has not found the way.
Upvotes: 44
Views: 160665
Reputation: 1
Two caveats for newbies like me when following official manual (I tried both adding shortcut to shell:startup and Task Scheduler, but I didn't succeed):
make sure the user/password exists in Windows 10. A user without a password won't install the service
.\VBoxAutostartSvc.exe install --user=Tim
Use netplwiz to solve Windows logon. Uncheck the box "Users must enter a user name and password to use this computer"
Finally, check again all "tim" was replaced when you copy the sample configuration file :-), I was stuck for hours to figure out why the configuration file couldn't be parsed.
Upvotes: 0
Reputation: 129
No. No. NOOOOOOOOO...
Have you ever heard about Task Scheduler??
That's exactly what it is here for.
Startup folder?
This is not a great solution for so many reasons.
The startup folder often not reliable, and if something went wrong you can't just check last run time, last state, etc…
Especially for this type of execution.
So let's bring in a good, trustworthy solution:
Open the Windows Task Scheduler.
To organize the whole thing neatly, create a new Folder under "Task scheduler Library" called "VMs".
(Or what ever you want to call it...)
Navigate to the folder you made and press "Create Task"
Name the Task
Select "run whether user is logged in or not"
Go to actions and press "New"
Action: Start Program
Program/Script: "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
Arguments: startvm your_vm_name --type headless
now go to "Trigger" and press "New"
choose System start and press ok
Done
You can try the task by starting it out of the task scheduler via right-click.
So again, why use this instead of startup folder? Startup folder works fine. But you MUST trust that everything is working fine as expected, and in enough cases it will just not, and you end up restarting your PC to try to fix it, etc... or in short it is just a huge PITA! :.)
Upvotes: 12
Reputation: 443
It is not possible to do what you are asking as a service without using a third-party wrapper (read: another point of failure) to your system. You can, however, easily implement this as a Task via Task Scheduler that will run every time your system boots/starts before a user ever logs in.
Information on that can be found in my answer in How can I run "Oracle VirtualBox (VBOX)" like a service after boot in fully background "Microsoft Windows (WIN)"?.
Upvotes: 7
Reputation: 411
Oracle VirtualBox 6.1.16 supports automatic startup via a Windows service without third-party scripts or software. These were the steps I followed. Replace my login with yours throughout.
Create a configuration file in C:\Users\Tim\.VirtualBox\autostart.properties
:
# Default policy is to deny starting a VM, the other option is "allow".
default_policy = deny
# Tim is allowed to start virtual machines but starting them
# will be delayed for 10 seconds
Tim = {
allow = true
startup_delay = 10
}
Add an environment variable for VBOXAUTOSTART_CONFIG
and set it to C:\Users\Tim\.VirtualBox\autostart.properties
.
Create the autostart service from an administrative PowerShell window:
cd "C:\Program Files\Oracle\VirtualBox"
.\VBoxAutostartSvc.exe install --user=Tim
.\VBoxManage.exe modifyvm "Peppermint x64" --autostart-enabled on
Find the VirtualBox Autostart Service tim@tim-pc service from the Services application.
Ensure the service login is your local login as configured above.
Ensure that automatic startup is enabled.
Start the service.
Check for errors in the Windows Event Viewer application under application logs. Error descriptions are under the "Details" tab.
Upvotes: 25
Reputation: 923
If you want to run the virtual machine even without logging in to the system, you can use the VBoxVmService utility which runs one or more VirtualBox machines in headless mode as Windows services and starts them automatically on boot.
Upvotes: 2
Reputation: 41
I needed a virtual machine running as a service—available from the network before user logged in first time—so fanxings' answer was an almost ideal solution.
The problem was VBoxManage starts the virtual machine and then simply exits. So service manager tries to run it again. And again. And again…
I've worked around this with a small batch file:
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm zztop --type headless
pause
This batch file was then installed as a service using nssm
. This solved the problem with closing the virtual machine using the GUI—e.g. for changing configuration—and prevented multiple error messages from showing up in the system log.
Upvotes: 4
Reputation: 6115
You can create a service for it by using NSSM. Example:
Open cmd
cd /d A:\programs\nssm-2.24\win64
nssm.exe install kubuntu
Fill the forms:
# Application Tab
Application Path: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe
Startup directory: C:\Program Files\Oracle\VirtualBox
Arguments: startvm "kubuntu" --type headless
# Details Tab
Display name: kubuntu
Click Install service, and done.
Upvotes: 10
Reputation: 12095
This worked for me.
Create a shortcut.
Add to Windows startup
Upvotes: 30
Reputation: 1695
I have an example of how to autostart a VirtualBox VM during Windows startup. I'm running Windows 10, but it shouldn't be much different on Windows Server 2016.
The startup folder on my system is:
C:\Users\chriwill\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
In that folder I placed a batch file kubuntu.bat
with following content:
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm kubuntu --type headless
In my example the VM is named kubuntu
. You'll have to change it for your instance.
Addon:
If you need help finding the startup folder on your windows instance press keys Windows + R and enter shell:startup
.
Reference: 8.19. VBoxManage startvm
Upvotes: 77
Reputation: 1
C:\Users\userid\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
folder.C:\Users\userid\VirtualBox VMs\vmname\vmname.vbox
.Windows should know *.vbox
file extension to open with VM VirtualBox.
You can set by use "open with" on vmname.vbox
.
Upvotes: 0
Reputation: 61
Scheduled task. Under actions, Program/scripts
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
Under Arguments
startvm Pihole --type headless
Upvotes: 6
Reputation: 560
There is a good choice to Add a Schedule Task. There is a plenty of options how it will warm up.
You can select run the task on startup regardless of user logins.
Upvotes: 2