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