21 Jun 2009 @ 8:40 PM 

vbox logo2 gradient How to run VirtualBox as service in WindowsAfter 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.
      enablevrdp thumb How to run VirtualBox as service in Windows
    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 Settings\YOURUSERNAME\.VirtualBox\ and open the file VirtualBox.xml with notepad.
      editvirtualboxxmlfile thumb How to run VirtualBox as service in Windows
    6. Press CTRL+F (find) and type "src" without quotes and press ENTER
      findsrc thumb How to run VirtualBox as service in Windows
    7. 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.
      originalsrc thumb How to run VirtualBox as service in Windows
      original src

      changesrcpath thumb How to run VirtualBox as service in Windows
      modified src
    8. Copy the file named VirtualBox.xml from C:Documents and Settings\YOURUSERNAME\.VirtualBox\ to C:Documents and Settings\LocalService\.VirtualBox\
      copytolocalservice thumb How to run VirtualBox as service in Windows
    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
      extractsrvstart thumb How to run VirtualBox as service in Windows
    12. 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
    13. Replace YOURUSERNAME above with your own windows user account, and YOURVMNAME with your own Virtual Machine’s name

      srvstartiniexample thumb How to run VirtualBox as service in Windows
    14. Close Notepad and save it as srvstart.ini in C:\VM

      saveinvmdir thumb How to run VirtualBox as service in Windows

    15. Run Windows Service Commander
    16. Click Tools > Install new service

      installnewservice thumb How to run VirtualBox as service in Windows
    17. The Service install wizard will show up, click Next
    18. Enter
      c:\VM\srvstart.exe svc YOURVMNAME -c "c:\vm\srvstart.ini"
    19. Again, replace YOURVMNAME above with your own Virtual Machine’s name

      pathtoserviceexe thumb How to run VirtualBox as service in Windows
    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)

      servicename thumb How to run VirtualBox as service in Windows

    22. Press Next
    23. Check the "Allow service to interact with desktop" option

      allowtointeractwithdesktop thumb How to run VirtualBox as service in Windows

    24. Press Next
    25. Leave the startup as Manual and error as Ignore for now

      manualignor thumb How to run VirtualBox as service in Windows
    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

      displayinservicelist thumb How to run VirtualBox as service in Windows
    30. Click on it and press the triangle button at the toolbar to start the service

      clickstart thumb How to run VirtualBox as service in Windows
    31. If the red round icon turns into green, then your VM is running as service successfully!

      servicerunning thumb How to run VirtualBox as service in Windows
    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 runs

      automatic 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 Settings\LocalService\.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: 11 Oct 2010 @ 12:33 AM

EmailPermalink
Tags


 

Responses to this post » (53 Total)

 
  1. sv000008 says:

    Here is my .ini file if anyone can spot anything wrong


    env=USERPROFILE=%SystemDrive%\Users\Default
    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:\Users\strider\.VirtualBox
    env=VBOX_MACHINES=C:\Users\strider\.VirtualBox\Machines
    env=VBOX_VDI=D:\VM Disks

    debug=2
    debug_out=>c:\srvstart\vm.log

    [IPCop]
    startup=%VBOXHEADLESS% -startvm IPCop
    shutdown_method=command
    shutdown=%VBOXMANAGE% controlvm IPCop acpipowerbutton
    #shutdown=%VBOXMANAGE% controlvm IPCop savestate

    [cmd]
    startup=c:\windows\system32\cmd.exe

    [notepad]
    startup=c:\windows\notepad.exe

  2. Brady says:

    Works as described.
    Got it working with Server 2008 R2 x64 Enterprise.
    Eve have UAC turned on without any issues.
    Thanks!

  3. JP says:

    Hi LDL, this looks great.

    Question – I have Windows 7 Workstation Professional tweaked to allow multiple RDP sessions. Basically, this is the same as Server.

    Can your ace hack mean that multiple users can log in and use virtualbox for an instance of e.g. XP Pro for some legacy software?

    Regards, and thanks again for the hack!

    JP.

  4. LiveDeviL says:

    @JP, Hello JP…
    I’m not sure if I got your point here. But if I’m not mistaken, you want to have an XP Pro vbox inside a Windows 7 Pro host, that will run some legacy software, and it’s accessible by multiple users simultaneously.

    If that’s the case, it is the XP Pro vbox that you need to hack to allow multiple RDP sessions (accessed using different user names), and not the host (in this case the Windows 7 Pro).

    That way, your users can run the legacy software installed in your hacked vbox by connecting to it via RDP by typing it’s name instead of the host name.

    some steps I can think of at the moment:
    You have Windows 7 Pro as host (not necessarily multiple RDP hacked) to host a vbox named “XP-vbox” installed with multiple RDP hacked XP Pro and all the legacy software needed. Make sure the XP-vbox’s network connection already set to bridged instead of NAT, and it has it’s own static IP address.

    Create new user accounts inside the XP-vbox as many as you need.

    To connect to this XP-vbox, your users need to connect via RDP, and put “XP-vbox” (ignore the quotes) in “Computer” field if they’re on the same IP segment, or put it’s IP address if they’re on different IP segment, and use their own user name and password respectively.

    good luck and CMIIW

    br,
    LD

  5. wma78 says:

    I only want to say thank you!!. Excelent tutorial!.

    Thanks to comments too, it gave me an idea about where was the problem.

    Its important to say that YOURVMNAME is case-sentive, and if you need to fix it in the Windows Service Commander, you must delete the entry first, and then add a new service again.

  6. Emin says:

    Thank you, it works! Good work!

  7. AMD20x6 says:

    Thank you! This tutorial certainly saved me a lot of headaches.

    I had to do a minor workaround for the VMs to start upon boot on a Windows Server 2008 R2 SP1 machine. Setting the service to automatic had no effect so I set them to manual instead. Then I created a scheduled task for each VM as follows:

    Trigger: At system startup
    Action: Start a program: sc start YOURVMSERVICENAME
    Change User or Group to SYSTEM

    Windows will still automatically send the shutdown command as defined in srvstart.ini when the machine shuts down.

  8. Emin says:

    Make sure the “env=USERPROFILE=…” line is NOT quoted, or srvstart.exe will report errors. This gave me a lot of headaches until I found this tip on virtualbox forums.

  9. Andrew says:

    Not free but AlwaysUpdoes a good job with our VBoxes

  10. Stephan says:

    I had an easier time just making a scheduled task that starts upon system start up. Just create a batch file with this line:

    C:\Progra~1\Oracle\virtualbox\VBoxHeadless.exe -startvm {UUIDHERE}

    Then add the scheduled task with the appropriate user information. It won’t be a service that has a few more parameters, but it will restart in the event of the system crashing.

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 » 30
  • Comments » 92
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight