After days of googling and a lot of trial and errors, I finally succeed running virtualbox as service. I tried VBoxVmService by mattz but have no luck. Then I tried another method with srvstart and Windows Service Commander explained here. It works for one Virtual Machine, but not for multiple Virtual Machines. While I need to run three Virtual Machines simultaneously. All without any user logged on! OK, enough talking, let’s start the tutorial…
-
Preparation
- I tried this only on Windows XP SP3 and Windows 2003 Server SP2 (I think it may works on Windows 2000 Server as well)
update: this method works on Windows Server 2008 (check Brian’s comment below) Thanks Brian!
update Sept 29th 2009 : it works on Windows Seven 64 bit (check Mr Incredible’s comment). Thanks Mr Incredible!
update Sept 29th 2009: it works on Windows Vista (check Victor Pajor’s comment below). Thanks Victor Pajor!
- SUN VirtualBox for Windows version 2.2.2 or more (download here)
update Oct 13th 2009: it works on Windows XP SP3 with VirtualBox 3.0.8 (check Kikeze’s comment below). Thanks Kikeze!
- srvstart (download here)
- Windows Service Commander (download here)
-
Installation
-
- Install SUN VirtualBox, create and configure your guest OS’s
- Make sure you click the Remote Display setting, and check the "Enable VRDP server" option. Then assign a port number like 3001, 3002, 3003, etc.
- Setup all your guest OS’s as needed (install applications, setup preferences, tweaks, etc.)
- Shutdown all your guest OS’s
- Go to C:\Documents and Settings\YOURUSERNAME\.VirtualBox\ and open the file VirtualBox.xml with notepad.
- Press CTRL+F (find) and type "src" without quotes and press ENTER
-
Edit the words
src="Machines\YOURVMNAMEYOURVMNAME.xml" into src="C:Documents and Settings\YOURUSERNAME\.VirtualBox\Machines\YOURVMNAME\YOURVMNAME.xml. Close the file, and click Yes when asked
"Do you want to save the changes?". If you have more than one Virtual Machines, then you must repeat this step and replace the paths to your Virtual Machines’s .xml file accordingly.
original src
modified src
-
Copy the file named
VirtualBox.xml from
C:Documents and Settings\YOURUSERNAME\.VirtualBox\ to
C:Documents and Settings\LocalService\.VirtualBox\
- Install Windows Service Commander
- Create a new directory C:\vm
- Extract the srvstart_run.v110.zip file to this C:vm directory
- Open notepad, copy and paste the code below
env=VBOXGUI="C:\Program Files\Sun\xVM VirtualBox\virtualbox.exe"
env=VBOXHEADLESS="C:\Program Files\Sun\xVM VirtualBox\vboxheadless.exe"
env=VBOXWEBSRV="C:\Program Files\Sun\xVM VirtualBox\vboxwebsrv.exe"
env=VBOXMANAGE="C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe"
env=VBOX_PROG="C:\Program Files\Sun\xVM VirtualBox\"
env=VBOX_BASE="C:\Documents and Settings\YOURUSERNAMEHERE\.VirtualBox\"
env=VBOX_MACHINES="C:\Documents and Settings\YOURUSERNAMEHERE\.VirtualBox\machines\"
env=VBOX_VDI="C:\Documents and Settings\YOURUSERNAMEHERE\.VirtualBox\HardDisks\"
env=USERPROFILE=%SystemDrive%\Documents and Settings\LocalService\
debug=1
debug_out=>C:\vm\vm.log
[YOURVMNAME]
startup=%VBOXHEADLESS% -startvm YOURVMNAME
shutdown_method=command
shutdown=%VBOXMANAGE% controlvm YOURVMNAME savestate
- Replace YOURUSERNAME above with your own windows user account, and YOURVMNAME with your own Virtual Machine’s name
- Close Notepad and save it as srvstart.ini in C:\VM
- Run Windows Service Commander
- Click Tools > Install new service
- The Service install wizard will show up, click Next
- Enter
c:\VM\srvstart.exe svc YOURVMNAME -c "c:\vm\srvstart.ini"
- Again, replace YOURVMNAME above with your own Virtual Machine’s name
- Press Next
- Enter any name you want in the Name and Display Name field (ie. My VM Service), then add some descriptions if needed (optional)
- Press Next
- Check the "Allow service to interact with desktop" option
- Press Next
- Leave the startup as Manual and error as Ignore for now
- Press Next
- Press Next again as there’s nothing to change here
- Click Finish
- Now you’ll see the new service name in the service list
- Click on it and press the triangle button at the toolbar to start the service
- If the red round icon turns into green, then your VM is running as service successfully!
- If everything’s work as expected, you can change the startup type of your service as automatic, so every time your host Windows OS runs, your VirtualBox service will also runs
- If you want to modify an existing Virtual Machine’s configuration (eg. add memory, etc), or add a new Virtual Machine, you must set the VirtualBox service’s startup type to manual first, shutdown all your guest OS’s, and restart the host OS. We do this so there is no process is locking up the VirtualBox.xml file. After restart, the .VirtualBox.xml file can be modified and recopied into C:\Documents and Settings\LocalService\.VirtualBox (see step no. 8 above)
- To control your Virtual Machines, you can use Remote Desktop Connection and put your host computer’s IP, followed by a colon and the port number u assigned in the Remote Display setting (see step no. 2 above) eg. 192.168.2.60:3001
- See the debug=1 line in the srvstart.ini file above? You can safely set it to debug=0 if no errors occurred when practicing this tutorial.
- This tutorial shows how to run a single Virtual Machine as service, next time I will write another tutorial to run multiple Virtual Machines like mine. Check out the tutorial to run multiple Virtual Machine!
- Source with some modifications from VirtualBox forum (rasker’s post)
- Snapshots will be added later.
Victor Pajor
Nice post here .. love to try it soon..
Hello, Thank you for the detailed guide. I’m finding some difficulties because of my installations. Can you please help me with this issue?
My machine folder and HDD folder is on a separate drive (E:VBox_Machines and E:VBox_HDD respectively).
Can you please tell me what changes are needed on the steps above?
I’ve changed the address on srvstart.ini step 19 and 20 to point to the folders above. And I’ve left my virtualbox.xml file unchanged since on the src section its already set as absolute path to drive E:VBox_MachinesMyVMMyVM.xml
But when starting the service I’m getting this error (from log):
SRVSTART: 2009/07/24 14:10:16 INFORMATION severity=0 thread=2856 source=D:HomeAuthorsrvstart.v110exeexe.cpp line=322 text=SRVSTART version 1.10 Copyright (C) 1998 – 2000 Nick Rozanski (Nick@Rozanski.com) (Distributed under the terms of the GNU General Public License as published by the Free Software Foundation)
SRVSTART: 2009/07/24 14:10:16 INFORMATION severity=0 thread=2856 source=D:HomeAuthorsrvstart.v110exeexe.cpp line=324 text=To hide the startup message run SRVSTART with switch -d 0
SRVSTART: 2009/07/24 14:10:16 ERROR severity=0 thread=2856 source=D:HomeAuthorsrvstart.v110dllCmdRunner.cpp line=358 text=Exception 6 in Class ‘CmdRunner’ method ‘start()’
SRVSTART: 2009/07/24 14:10:16 ERROR severity=0 thread=2856 source=D:HomeAuthorsrvstart.v110exeexe.cpp line=334 text=Exception 6 trapped in source file ‘D:HomeAuthorsrvstart.v110dllCmdRunner.cpp’ line 358
SRVSTART: 2009/07/24 14:10:16 ERROR severity=0 thread=2856 source=D:HomeAuthorsrvstart.v110exeexe.cpp line=335 text=Class ‘CmdRunner’ method ‘start’
SRVSTART: 2009/07/24 14:10:16 ERROR severity=0 thread=2856 source=D:HomeAuthorsrvstart.v110exeexe.cpp line=336 text=An invalid parameter was supplied to a function or method.
SRVSTART: 2009/07/24 14:10:16 ERROR severity=0 thread=2856 source=D:HomeAuthorsrvstart.v110exeexe.cpp line=449 text=SRVSTART is terminating with a FAILURE status
Why some of the file is pointing to D: I’m not sure.
Can you please help?
Thank You
@swh
hello…
i’ll see what i can do to help…
1. can u paste here the content of your srvstart.ini file?
2. make sure the VM name u gave in virtualbox is in the exact case as in the srvstart.ini and in the commandline in windows service commander (see step 19). so eg. ur VM name is MyServer, then u must put MyServer in srvstart.ini and in windows service commander. not MYSERVER or myserver.
3. please paste what u typed in step 19 in windows service commander.
Ah, I see… my bad….
After some trials over the weekend, I found out that I havent change the text in the bracket to my virtual machine name.
It’s solved now. Your tutorial works perfectly. Thank You again for the detailed tutorial.
You’re always welcome…
I’m glad this tutorial helps…
You Rock
I had tried 3 other tutorials b4 urs.
Thank you…
hope this tutorial helps u…
LiveDevil-
I just used your tutorial as a guide to get virtualbox starting a VM automatically on Windows Server 2008. I needed to change the paths in srvstart.ini to “C:\Users”, and turn off UAC, but ti worked as advertised. Thanks so much for posting this. You rock.
Brian Hershey
Thank you Brian for confirming that this method works on Windows Server 2008… i’ll update the post to include this information… i think it might be useful for other people…
Hi LiveDevil !
I want to run as virtualbox as service on sbs 2008 and it don’t work. I’ve done the same thinks as Brian. Not OK. He says he has turn off UAC. I’ve change UAC to user level but any change. How can i do the correct config in my .ini. Thanks for your help.