Skip to content

Making VirtualBox More Seamless

by mrchris on June 21st, 2010

VirtualBox is one of my favorite Virtualization tools. While my primary OS is Linux I still need to visit Windows from time to time to test in IE, Safari, or to use some specific oddball program. The latest versions of VirtualBox starting with version 3.2 has a new feature that makes these trips to Windows a little less painful.

Many are aware of VirtualBox’s seamless mode. For those who aren’t see this video to understand what it is. While seamless mode is old news, what isn’t is the ability to launch applications in the guest operating system directly from the host with the VBoxManage command line tool. For example, running Linux as the host OS and Windows XP as the guest I can launch IE with the command

"VBoxManage guestcontrol execute "Windows XP" "C:\Program Files\Internet Explorer\iexplore.exe" --username windowsusername

Replacing “windowsusername” with the username you use to log in to the Windows guest and “Windows XP” with the name you gave your guest OS in VirtualBox. Arguments can also be passed to the program being launch in the guest OS with the –arguments flag. For example

VBoxManage guestcontrol execute "Windows XP" "C:\Program Files\Internet Explorer\iexplore.exe" --username windowsusername --arguments "http://google.com"

While this is all well and good, it is not exactly convenient. In your respective desktop environment it would be relatively simple to create a launcher that can execute this command but it falls short on truly integrating it with the OS. What about the ability to right click on a file on your host desktop and have it open in it’s respective Windows based program. Using Windows notepad as a simple example, here’s how to do just that.

First, be sure that you have the VirtualBox guest additions installed. Then, in your VirtualBox settings, create a permanent shared folder in your guest OS to your host’s home directory. This will give it the access it needs to open files from your host’s file system.  After that, in “/usr/local/bin” create an executable bash script named “notepad” and paste into it this code.

#!/bin/bash
oldPath=${1//\/home/\/\/VBOXSVR}
newPath=${oldPath//\//\\}
VBoxManage guestcontrol execute "Windows XP" "C:\Windows\notepad.exe" --username windowsusername --arguments "$newPath"

This simple script takes the full file path that gets passed in and converts it to a valid Windows path. What goes in as “/home/username/Desktop/test.txt” would become “\\VBOXSVR\username\Desktop\text.txt”. The path then gets passed to the guest OS’s program for opening. Save that file and don’t forget to give make it executable with

chmod +x /usr/local/bin/notepad

In your respective desktop environment (mine is Gnome) create a file called test.txt on your desktop and associate the command “/usr/local/bin/notepad” to it. With Gnome this is done by right clicking on the file, clicking “Properties”, going to the “Open With” tab and clicking the “Add” button. An “Add Application” dialog will pop up. In that window, expand the “Use a custom command” dropdown and enter “/usr/local/bin/notepad” into the textfield provided. Then click the “Add” button then the “Close” button.

To get the full effect, put your guest OS into seamless mode then right click on “test.txt” on your desktop, mouse over “Open With”, then click on “notepad”. If you did everything correctly the Windows notepad should launch with the contents of “test.txt”. Here’s a video of the whole thing put together.

This example can be applied to any Windows program. With a little modification, the script can be applied to other guest operating systems as well.

From → Linux

2 Comments
  1. Hammad permalink

    VBoxManage: error: Machine “Windows” is not running (currently powered off)!

    do i have to launch the machine first.. can’t the shortcut automatically launch the virtualmachine and then launch the program in it?

    • mrchris permalink

      Yes, it has to be running. It’s not a limitation of the shortcut but of VirtualBox. You can’t communicate with a guest OS if the guest OS isn’t running.

      You could, if you really wanted to, write a script around it that launches the virtual machine, gets the status when you try to launch the program in the guest OS while it’s booting, and stop trying when no error is returned.

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS