Skip to content

VirtualBox Enhancement for Opening WinXP Applications

by peter on November 16th, 2008

This guide explains how to open Microsoft Word Files from an Ubuntu host in Microsoft Word using a Windows XP Virtual Machine. In fact, this mechanism can be used to open lots of file types in seamlessly in any Guest from any Host. This extensions builds upon the seamless integration provided by VirtualBox to create a more convenient user interface for using multiple operating systems in parallel.

Motivation

I use VirtualBox to open Microsoft Word programs on my Ubuntu host in my Windows XP Virtual Machine. I found this was extremely frustrating, firstly finding the file in my Ubuntu, then navigating to the same file in my Windows Virtual Machine and so I requested a new feature: http://www.virtualbox.org/ticket/2482, to run commands in my Windows Guest Machine from my Ubuntu Host.

Brief Overview

The application launcher installation involves four main steps:

  1. Share of Ubuntu Host folders
  2. Mapping of Host folders in Windows XP guest
  3. Write a Script in Ubuntu Host, used to send file names to open
  4. Write a Script in Windows XP Guest, listening for file names to open

Technical Detail

The file name is sent from the Host Machine to the Guest Machine using a VirtualBox guestproperty which both the Host and Guest Machines can access. This is periodically checked by the Guest Machine, launching the file using Window XP’s default launcher.

Share of Ubuntu Host folders

The Windows Virtual Machine needs to access Host’s files. Only shared files can be opened on the Window’s Virtual Machine. I found VirtualBox’s shared folders too slow, so I shared my ubuntu root using samba; so the files on my hardisk are accessible on the network using //my-laptop/root. This is a potential security risk, so I configured Samba to require credentials (there is also a I.P. filtering option). For people concerned about security, I’d recommend sharing only your Documents folder.

To recap, share your root folder, or a ‘Documents’ folder. Note only files in this directory can be opened on the Virtual Machine.

Mapping of Host folders in Windows XP guest

Having presented your Documents folder on the network, map the network drive to Z: (this drive letter is configurable in the Window’s Script listed below). I found that on a starting my Windows Virtual Machine my machines hostname was not accessible immediately, if you rarely change networks considering using your I.P. which can be resolved instantly.

Write a Script in Ubuntu Host, used to send file names to open

We need a Bash Script to be run in Ubuntu to send the document’s filename to a named Window’s Virtual Machine. This script expects a Virtual Machine called ‘WinXP’, change this reference if your Window’s Virtual Machine name is different.

This script should be used to open Word files, instead of OpenOffice, this can be specified the ‘Open with Other Applications’ menu item, when right clicking on a word file. Don’t forget to make the file executable, using:

chmod +x vmword.sh

If you experience difficulties with this step try running the script from the command line, checking /tmp/vmword.log for output.

# This program sends all arguments to a guest property called ‘wordfile’ for a Virtual Machine called ‘WinXP’
VBoxManage guestproperty set WinXP wordfile “$*” > /tmp/vmword.log

Write a Script in Windows XP Guest, listening for file names to open

We now need a more complex Window’s Batch Script to receive and open the filename. This should be started on Window’s startup, by copying into the Startup folder in the Windows Startup Menu; there may be better ways to make this a daemon.

I am unfamiliar with Batch Programming, so this script could probably be neatened, but it does the following:

  1. Checks for new filenames every second (unfortunately using inefficient polling)
  2. Converts the filename from the Linux Location to the Windows location
  3. Opens the file

The script requires the sleep program, this is included the rktools.exe, which can be downloaded from: http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

The filename conversion process is dependent on which folder you shared, and which drive is mapped to that share.
My conversion process is basic and does the following:

  1. Removes ‘Value: ‘ from the Value returned from the VBoxcommand
  2. Prefixes filename with ‘z:’

@echo off
rem This batch script listens to the guestproperty ‘wordfile’ for its machine.
rem The program checks to see if a value is set, and if so, changes the name from
rem ‘/file.doc/’ to ‘z:/file.doc’
rem The word file is then opened in a new cmd window executing the filename, which opens in the default application.
rem This program requires sleep, which is included in rktool.exe to be installed from
rem http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

:start

sleep 1
VBoxControl -nologo guestproperty get wordfile | find /v “No value set!” > read.txt

if errorlevel 1 goto start

rem Read file and get filename and convert

type read.txt
setlocal enabledelayedexpansion
set SEPARATOR=/
set filecontent=
set root=z:
for /f “delims=” %%a in (‘type read.txt’) do (
set currentline=%%a
set filecontent=!currentline!
)

rem trim string; removing VirtualBox text
set filecontent=%filecontent:~7%

set overallfilecontent=”!root!%filecontent%”

echo The file contents are: %overallfilecontent%

rem start program
start cmd /C %overallfilecontent%

rem delete filename from guestproperty.
VBoxControl -nologo guestproperty set wordfile

goto start

From → IT

One Comment
  1. Tobias Bosch permalink

    Thanks very much for this post!
    I changed it a little by not using the sleep command, but the “VBoxControl guestproperty wait” instead of the “VBoxControl guestproperty get” command, so there is no delay at all when opening files.

Leave a Reply

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

Subscribe to this comment feed via RSS