I want to run autostart "Virtual Machine (VM)" without "Oracle VirtualBox (VBOX)" "Graphical User Interface (GUI)" on a local development machine with "Microsoft Windows (WIN)".
How can I do that in fully running background process?
I want to run autostart "Virtual Machine (VM)" without "Oracle VirtualBox (VBOX)" "Graphical User Interface (GUI)" on a local development machine with "Microsoft Windows (WIN)".
How can I do that in fully running background process?
The trick is to run the VM without GUI. With this you can easily run VM on WIN server like a service too.
Prerequired is that exist some VM, you have some already. Below put its name instead {vm_name}
.
Use build-in executable file "VBoxHeadless.exe".
Create file
vm.run.bat
with
cd "c:\Program Files\Oracle\VirtualBox\"
VBoxHeadless.exe -s {vm_name} -v on
run and test it - with WIN "Command Line Interface (CLI)" called "Command shell" - and VM will be opened running in background.
vm.run.bat
Use "Windows-based script host (WSCRIPT)" and language "Microsoft Visual Basic Script (VBS)" and run above file "vm.run.bat".
Create file
vm.run.vbs
put code
Set WshShell = WScript.CreateObject("WScript.Shell")
obj = WshShell.Run("vm.run.bat", 0)
set WshShell = Nothing
run and test it - CLI will be run in background
wscript.exe vm.run.vbs
Ref
You can use VBoxManage to start a VM headless:
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm "Your VM name" --type headless
I used something similar to Samuel's solution that works great.
On the desktop (or any folder), right-click and go to New → Shortcut.
In the target, type:
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm {uuid} --type headless
In the name, type whatever you want and click Finish.
Then to stop the same VM, create a new shortcut with the target being:
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm {uuid} poweroff
double-clicking these starts and stops the VM without any window staying open.
The truly most-consistent option is to use Task Scheduler.
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:
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
.
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 prerequisite 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 three 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!
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):
On another machine, I set up my Linux server as a virtual machine with its 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.
An alternative solution: vboxsvc - VirtualBox SMF service wrapper
It works perfect for me!
If you do not mind operating the application once manually, to end with OS running in background; here are the options:
Open Virtual Box. Right Click on your Guest OS > Choose: Start Headless. Wait for a while till the OS boots.
Then close the Virtual Box application.
Following Bruno Garett's answer, in my experience: testing the vm.run.bat
file fails. It gives a read-only error, but it will work fine running VBScript.
Also to shut down headless, you can use another batch script (Sam F's solution won’t work with Bruno's solution):
cd "c:\Program Files\Oracle\VirtualBox\"
VBoxManage controlvm "Ubuntu Server" acpipowerbutton
The second line was obtained from here. You can use whichever option you want.