Update: I’d suggest checkout out James’ solution in the comments as an alternative to mine which doesn’t require 3rd party programs. I haven’t tested it yet so let me know if it works OK for you.
I’ve seen a few tutorials out there about setting up a headless Virtualbox service in windows in order to autostart a VM and wasted a few hours of my life following pages of instructions ending in giving up. I recently reinstalled windows 7 on my home HTPC/Server and wanted a linux VM to autostart whenever Windows decided to run updates and auto restart. I swore I wouldn’t attempt the awful services method again and would insead follow the principle of keep it simple stupid.
My only caveat in setting up this autostarting headless VM was that Windows 7 remain password protected when it started up (task scheduler’s on start trigger function didn’t prove much help with this goal BTW)…a little less simple but I managed to keep it under 3 steps somehow, mostly thanks to superuser’s superb knowledge base and some luck googling. Keep in mind I have a single user setup on this windows 7 machine. Multiple users might require you force the machine to always logon to your VirtualBox/Startup script user by default after a reboot…so you’ve been warned. Here’s how it’s done:
- download hstart (see README)
- Remove/un-check the “User must enter a username and password to use this computer” checkbox option from Start -> Run -> `control userpasswords2` (But wait…didn’t you just say…YES KEEP READING)
- write a batch script in your startup folder containing (psudocode): C:/hstart.exe /NOCONSOLE “VMBoxHeadless.exe -start-vm ‘your-vm-name'” followed by “rundll32.exe user32.dll,LockWorkStation”
The name VMBoxHeadless is a bit misleading since you still have a cmd window to leave open as long as you want your VM running if you run it through a batch script, that’s where hstart comes in. Then you have to tell windows to logon automatically instead of waiting for the user to enter a username/password. Finally your batch script run VMBoxHeadless through hstart and then just re-locks your computer afterwards and you have a primed and ready VM waiting for you upon restart. If your VM name has spaces it might require escaped quotes or single quotes around it, I used a hyphen in my name so I didn’t have to deal with that problem.
Here’s an eaxmple batch script
C:\Users\HTPC\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\hstart a-serv headless.bat:
"E:\scripts\hstart64.exe" /NOCONSOLE "C:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe -startvm a-serv" rundll32.exe user32.dll,LockWorkStation |
References (yay superuser!)
What is the best way to hide a command prompt window?
Command line cmd command to lock a windows machine
Which version of Windows 7 (Home Premium, Pro, Ultimate) would you recommend for this?
Any version should work. There are no premium/pro/ultimate features used in this setup.
Nice but what about saving the guest machine state on Windows shutdown/reboot?
I typically run shutdown -h now from ssh. I admit I have had to uncleanly shutdown a couple times when ssh wasn’t working. but there’s always the RDP built into vbox.
I was thinking about a way to save the state or to cleanly shutdown the guest when the Windows host shuts down (and I forget about the headless guest)
Good thought, I rarely restart the machine I set this up for since it’s my home server / HTPC. Let me know if you come up with something!
I finally used http://sourceforge.net/projects/vboxvmservice/ although there’s a slight delay on startup.
I could still use your script for a faster startup or this other solution http://timita.org/wordpress/2011/08/04/protect-windows-with-pfsense-and-virtualbox-part-6-running-virtualbox-headless-vm-auto-save-stateresume/
Pingback: Virtualbox headless, sin interfaz gráfica, en Windows | Ngaby.com
Hi guys,
Sorry to revive an old thread, but I have a solution to this issue where I have written a script that does all that you want:
1) without requiring hstart and the command prompt window does disappear.
2) It launches the VM as a seamless/headless/maximised
3) Even if you did somehow manage to close the terminal/cmd window it WILL NOT pull the plug on your virtual machine!
4) If you look at the script it not only allows for that safety factor but it actually starts it in a fresh new process and closes the CMD window for you anyway, this way you leave the virtual machine open and running in its own process 😉
5) It IDs the Virtual machine via its ID number and not its name and location so Virtualbox automatically knows what virtual machine you wish to launch without needing to know its path location in reference to the script location
[code]@echo off
if not “%minimized%”==”” goto :minimized
set minimized=true
start /min cmd /C “%~dpnx0”
goto :EOF
:minimized
rem Anything after here will run in a minimized window
rem bring the current directoty forward and change drives cause windows normally starts your process from system32
rem bringing the process forward to the script location means it will launch myscript from its location
%~d0
CD %~dp0
cls
rem Open the folder in a new process and close/exit this one
start /wait /b C:\PROGRA~1\Oracle\VirtualBox\VirtualBox.exe –startvm “6de1a76e-ee30-4844-b578-a2453026c14e” /SEPARATE/N
exit[/code]
Note that code is for my own Virtualbox Ubuntu ID, put yours in there. If you like
Basically plonk this on your desktop or in your startup folder and create a user called Ubuntu in Windows 7 and use the same credentials in Win7 as Ubuntu. Set the screen in Win7 never to lock or require password to unlock. Set boot into Ubuntu to auto-log in but have password prompt on screen awake resume! DONE