Running VirtualBox in Headless Mode

At work I have ReviewBoard running on VirtualBox on one of my development machines.  This has been working great but every once in awhile I accidentally close the VirtualBox console because it’s sitting in my taskbar:

VirtualBox in taskbar

VirtualBox in Taskbar

I remember reading about a ‘headless’ mode in the VirtualBox documentation.  This will setup VirtualBox running as a RDP server – it can run ‘invisibly’ and you can connect via Windows Remote Desktop to intact with the system.

You can either configure the remote settings within the VirtualBox GUI:

Remote Display Dialog

Remote Display Dialog

Or pass them in through the command line.  I went this route and created a batch file called start-reviewboard.bat:

REM  Batch script to start VirtualBox instance of ReviewBoard in headless mode
REM  Connect via RDP (Remote Desktop Protocol) to port 8000

"C:\Program Files\sun\VirtualBox\VBoxHeadless.exe" -startvm ReviewBoard -p 8000

This starts VirtualBox in headless mode (VBoxHeadless.exe), starts my ReviewBoard vm, and sets up RDP (port 8000).

You can run this script and it should start VirtualBox – but you will still be left with a DOS box sitting there in your taskbar. Turns out it is fairly easy to write a small script to run a batch file silently as well. I created start-reviewboard.vbs:

REM 0 = hide window, 1 = show window (useful for debugging)

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "D:\scripts\start-reviewboard.bat" & Chr(34), 0
Set WshShell = Nothing

You use this script to run your batch file and pass in a parameter to hide the window (0). I’d recommend setting that to 1 while you get things setup so you can see what is going on and once you have worked out the kinks set it to 0.

When you run it – you should get a DOS window and a message “Listening on port 8000” (or whatever you set the port to). I changed the port to 8000 as I assume Windows is already using 3389 (default RDP port).

To connect I simply start Remote Desktop Connection and enter localhost:8000.

To stop VirtualBox simply issue the following command:

VBoxManage controlvm YOUR_VM_NAME poweroff
Recent Related Posts

11 thoughts on “Running VirtualBox in Headless Mode

  1. This is great. Thanks!

    Also, just to let you know, the vbs script has” &” instead of “&”. If someone reading this didn’t know anything about VB, then this might really be confusing.

    Thanks again!

  2. change “C:\Program Files\sun\VirtualBox\VBoxHeadless.exe” -startvm ReviewBoard -p 8000
    to
    start “” “C:\Program Files\sun\VirtualBox\VBoxHeadless.exe” -startvm ReviewBoard -p 8000

    In batch files, calling the executable directly will make it wait for execution to complete (start /wait). using “start” will continue the script and exit, leaving you with a running vbox, no cmd window, and no messy leftover processes.

  3. They for the info!

    You can skip the batch file step and run this headless right from your vb script like so.
    dim strScript
    strScript = chr(34) & "C:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe" & chr(34) & " -startvm ubuntu-dev -p 8000"
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run strScript, 0
    Set WshShell = Nothing

  4. This is much better. Everything goes into one VBS file and it launches!

    Hint: Open VirtualBox Manager to check whether the VirtualMachine is running! :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

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