srvstart.exe is a tool written by Nick Rozanski for running any application or script using the Windows service manager.
setup your VM... (e.g. setup static ip, install guest additions, etc.)
copy the virtualbox.xml file from your vm:
c:\Documents and Settings\
to c:\Documents and Settings\LocalService.VirtualBox\ directory
(create the .VirtualBox directory if it doesn't already exist.)
This allows VirtualBox to get the right config when it is executed from the LocalService account.
Create a directory in c:\Program Files\ called srvstart.
Copy (extract) all the files from within the zip archive to srvstart (particularly, logger.dll, srvstart.dll, srvstart.exe, svc.exe)
create a file called
e.g. c:\program files\srvstart\testVM.srvstart.ini
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="d:\vbox\" env=VBOX_MACHINES="d:\vbox\machines" env=VBOX_VDI="d:\vbox\VDI" env=VBOX_MACHINE1=vbox_linsrv
[VBOX_LINUX] startup=%VBOXHEADLESS% -startvm VBOX_LINUX shutdown_method=command shutdown=%VBOXMANAGE% controlvm VBOX_LINUX savestate debug=0 debug_out=>d:\vbox\VDI\VBOX_LINUX.log
Start Windows Service Commander and select Tools -> Install New Service from the menu. this will start a wizard to help you set the service up. Click Next In the Enter Path to the service executable: box, click Browse and browse to and select the c:\Program Files\srvstart\srvstart.exe file. Append the following to the command line : svc VBOX_LINUX -c "c:\Program Files\srvstart\srvstart.ini" check that it looks something like :
c:\Program Files\srvstart\srvstart.exe svc VBOX_LINUX -c "c:\Program Files\srvstart\srvstart.ini"
Leave the Service will run in it's own process radio button selected and click Next. Give your service a name e.g. VBOX_LINUX,
a Display Name (which can be the same as the Service Name)
a brief description of the virtual machine.
Leave the LocalSystem account radio button selected and click the Allow service to interact with desktop checkbox. Click Next.
Set the startup options as you wish (defaults are good for now). Click Next twice (skip the Dependencies page) and click Finish.
Don't assign a startup_dir keyword if the startup directory has white space in it.
The parameter after the svc parameter in the service command line should be exactly the same as the keyword in the ini file which is enclosed in square brackets. Within the ini file, you can change the virtualbox machine name to your own virtual machine (the parameters after the startvm and controlvm switches).
The key reason to use srvstart is because we can stop the virtual machine in the correct way (the above configuration saves the state) by using the vboxmanage controlvm command. You could also try an acpi shutdown. Saving state and closing is probably good enough though.
If possible define the vrdp port number in the machine settings not the vboxheadless command line if you are using the savestate method of shutting down. You can get a conflict which prevents the virtual machine from starting up.
Stopping the service usually successfully terminates the vboxheadless processes. Unfortunately the VBoxSvc process does not always do the right thing and go away. This is particularly true if you start the virtualbox Gui while the service is started. This can leave locked files behind which prevent you from either starting the virtualbox gui or accessing the machine from the gui if the gui can be started and other issues.