21 Jun 2009 @ 8:40 PM 

vbox_logo2_gradientAfter 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

    1. 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!
    2. 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!
    3. srvstart (download here)
    4. Windows Service Commander (download here)
  • Installation

    1. Install SUN VirtualBox, create and configure your guest OS’s
    2. 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.
      enable VRDP
    3. Setup all your guest OS’s as needed (install applications, setup preferences, tweaks, etc.)
    4. Shutdown all your guest OS’s
    5. Go to C:Documents and SettingsYOURUSERNAME.VirtualBox and open the file VirtualBox.xml with notepad.
      edit .virtualbox.xml file
    6. Press CTRL+F (find) and type “src” without quotes and press ENTER
      find src
    7. Edit the words src=”MachinesYOURVMNAMEYOURVMNAME.xml into src=”C:Documents and SettingsYOURUSERNAME.VirtualBoxMachinesYOURVMNAMEYOURVMNAME.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
      original src

      change src path
      modified src
    8. Copy the file named VirtualBox.xml from C:Documents and SettingsYOURUSERNAME.VirtualBox to C:Documents and SettingsLocalService.VirtualBox
      copy to localservice
    9. Install Windows Service Commander
    10. Create a new directory C:vm
    11. Extract the srvstart_run.v110.zip file to this C:vm directory
      extract srvstart
    12. Open notepad, copy and paste the code below
      env=VBOXGUI="C:Program FilesSunxVM VirtualBoxvirtualbox.exe"
      env=VBOXHEADLESS="C:Program FilesSunxVM VirtualBoxvboxheadless.exe"
      env=VBOXWEBSRV="C:Program FilesSunxVM VirtualBoxvboxwebsrv.exe"
      env=VBOXMANAGE="C:Program FilesSunxVM VirtualBoxVBoxManage.exe"
      env=VBOX_PROG="C:Program FilesSunxVM VirtualBox"
      env=VBOX_BASE="C:Documents and SettingsYOURUSERNAMEHERE.VirtualBox"
      env=VBOX_MACHINES="C:Documents and SettingsYOURUSERNAMEHERE.VirtualBoxmachines"
      env=VBOX_VDI="C:Documents and SettingsYOURUSERNAMEHERE.VirtualBoxHardDisks"
      env=USERPROFILE=%SystemDrive%Documents and SettingsLocalService
      
      debug=1
      debug_out=>C:vmvm.log
      
      [YOURVMNAME]
      startup=%VBOXHEADLESS% -startvm YOURVMNAME
      shutdown_method=command
      shutdown=%VBOXMANAGE% controlvm YOURVMNAME savestate
    13. Replace YOURUSERNAME above with your own windows user account, and YOURVMNAME with your own Virtual Machine’s name
      srvstart.ini example
    14. Close Notepad and save it as srvstart.ini in C:VM
      save in vm dir
    15. Run Windows Service Commander
    16. Click Tools > Install new service
      install new service
    17. The Service install wizard will show up, click Next
    18. Enter
      c:VMsrvstart.exe svc YOURVMNAME -c "c:vmsrvstart.ini"
    19. Again, replace YOURVMNAME above with your own Virtual Machine’s namepath to service exe
    20. Press Next
    21. Enter any name you want in the Name and Display Name field (ie. My VM Service), then add some descriptions if needed (optional)
      service name
    22. Press Next
    23. Check the “Allow service to interact with desktop” option
      allow to interact with desktop
    24. Press Next
    25. Leave the startup as Manual and error as Ignore for now
      manual ignor
    26. Press Next
    27. Press Next again as there’s nothing to change here
    28. Click Finish
    29. Now you’ll see the new service name in the service list
      display in service list
    30. Click on it and press the triangle button at the toolbar to start the serviceclick start
    31. If the red round icon turns into green, then your VM is running as service successfully!service running
    32. 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 runsautomatic thumb How to run VirtualBox as service in Windows
  • Notes
  1. 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 SettingsLocalService.VirtualBox (see step no. 8 above)
  2. 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
    rdc thumb How to run VirtualBox as service in Windows
  3. 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.
  4. 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!

  5. Source with some modifications from VirtualBox forum (rasker’s post)
  6. Snapshots will be added later.
Victor Pajor



Posted By: LiveDeviL
Last Edit: 13 Oct 2009 @ 09:59 AM

EmailPermalink
Tags


 

Responses to this post » (34 Total)

 
  1. Mr Justin says:

    is there any way to supress that “Interactive Services Dialog” screen that comes up? When i uncheck “Allow service to interact with desktop” the service doesnt work.

    LiveDeviL Reply:

    @Mr Justin, I’m not sure about that. but they don’t bother me much as I’m not monitoring the host directly in front of it’s screen. the main purpose is to get vbox run as a service without any interaction at all from us the user (or admin), even without the need to login first… :)

  2. George Tudor says:

    here is how to hide the system windows:

    1. download this tool http://www.nirsoft.net/utils/nircmd.html
    2. extract the files to c:\vm\nircmd
    3. in c:\documents and settings\all users\start menu\programs\startup

    create a file called hidevm.bat containing the following line:

    c:\vm\nircmd\nircmd win hide ititle “vboxheadless”

    voila!

    there may be a way to set this up as a service, but I got some error and didnt have time to deal with it right now :-)

    thanks for the great post!

  3. Nepumuck says:

    Hey, thanks for this tutorial :)

    After hours, now the service runs under Win2008 Server (32bit).
    The trick was _no_ quotes in the .ini file.
    Ignore the whitespaces!!!


    env=VBOXGUI=C:\Program Files\Sun\virtualbox\VirtualBox.exe
    env=VBOXHEADLESS=C:\Program Files\Sun\VirtualBox\VBoxHeadless.exe
    env=VBOXWEBSRV=C:\Program Files\Sun\VirtualBox\vboxwebsrv.exe
    env=VBOXMANAGE=C:\Program Files\Sun\VirtualBox\VBoxManage.exe
    env=VBOX_PROG=C:\Program Files\Sun\VirtualBox\
    env=VBOX_BASE=C:\Users\Administrator\.VirtualBox\
    env=VBOX_MACHINES=D:\Virtual Machines\VMs\
    env=VBOX_VDI=D:\Virtual Machines\HDDs\
    env=USERPROFILE=C:\Users\Administrator

  4. vbox 3.2.6 changes says:

    This works with the new oracle vm 3.2.6 if anyone is interested. All you have to do is change a few paths in your srvstart.ini Another trick i had no .virtualbox folder on my %SystemDrive%\Documents and Settings\LocalService
    on Win Xp SP3
    So I made the xml file change and instead of copying the xml file i just copied the virtual box folder to the LocalService folder.

    Note the changes in some of the capitalization and path changes in the srvstart.ini…. Everything else in the article worked the same.

    env=VBOXGUI=”C:\Program Files\Oracle\VirtualBox\VirtualBox.exe”
    env=VBOXHEADLESS=”C:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe”
    env=VBOXWEBSRV=”C:\Program Files\Oracle\VirtualBox\vboxwebsrv.exe”
    env=VBOXMANAGE=”C:\Program Files\Oracle\VirtualBox\VBoxManage.exe”
    env=VBOX_PROG=”C:\Program Files\Oracle\VirtualBox”
    env=VBOX_BASE=”C:\Documents and Settings\YourUserId\.VirtualBox”
    env=VBOX_MACHINES=”C:\Documents and Settings\YourUserId\.VirtualBox\Machines”
    env=VBOX_VDI=”PathToYourVdiFile”
    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

  5. Steve says:

    Hi, Okay so I followed you instructions and change a few things by the comments bellow the instructions, and it I tried to start the service and it is stuck on the little screen called Service Control that pops up with the loading bar and it says “Starting Service….” “The name I gave the service”
    and the loading bar is completely at 100% and it is stuck there, do you have any ideas on what it could be.

    LiveDeviL Reply:

    @Steve, Hello. First of all, I apologize for my late reply.

    About the stuck problem,
    1. have you set the service’s Startup Type to disabled (or manual) before making any changes to the VM’s configuration?
    2. when the “Starting Service…” screen popped up and the loading bar was completely at 100%, what was the VM status?
    3. when you run the VM manually, does it shows any error?

  6. Steve says:

    I found an easier way if you would like to know http://www.ehow.com/how_4888308_use-via-remote-desktop-connection.html It works on Windows XP Pro 32 bit

    LiveDeviL Reply:

    @Steve, thanks for the URL. but I think this method is only to make it easier and faster to run VM without the need of opening the virtualbox GUI first. so it serves a different purpose compared to “as service” method. the whole point of this “as service” method is to start one or multiple VM’s automatically when the host is started, and save the VM’s last state (or shutdown if configured so) when the host is shutdown or restarts, without any action from any user in that host. hope it helps. :)

  7. sierrj says:

    Gracias, trabaja de maravilla en Server 8, con algunos cambios claro

    LiveDeviL Reply:

    @sierrj, Usted es siempre bienvenido. :)

Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


 Last 50 Posts
Change Theme...
  • Users » 1
  • Posts/Pages » 27
  • Comments » 44
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight