Passing data between the VirtualBox Host and the Guest

Here's a good question: "How can you figure out the VM name from within the VM itself?"

While this data is not automatically available, the general purpose, and very powerful VirtualBox "GuestProperty" APIs can be used from the host and guest to pass arbitrary data, in key/value pairs format, in and out of the guest. Note that this does require that the VirtualBox Guest Additions have been installed in the guest.

To play with this, try using the "VBoxManage" command line on your VirtualBox host machine, and "VBoxControl" in the guest.

Host syntax

VBoxManage guestproperty    get <vmname>|<uuid>
                            <property> [--verbose]

VBoxManage guestproperty    set <vmname>|<uuid>
                            <property> [<value> [--flags <flags>]]

VBoxManage guestproperty    enumerate <vmname>|<uuid>
                            [--patterns <patterns>]

VBoxManage guestproperty    wait <vmname>|<uuid> <patterns>
                            [--timeout <msec>] [--fail-on-timeout]  

Guest syntax

VBoxControl.exe guestproperty        get <property> [-verbose]
VBoxControl.exe guestproperty        set <property> [<value> [-flags <flags>]]
VBoxControl.exe guestproperty        enumerate [-patterns <patterns>]
VBoxControl.exe guestproperty        wait <patterns>
                                     [-timestamp <last timestamp>]
                                     [-timeout <timeout in ms> 

So to solve our problem above, we set the vm name in the Host system on an arbitrary key like this:

$ VBoxManage guestproperty set "Windows 7 (x64)" /MyData/VMname "Windows 7 (x64)"

And within the guest we can use:

C:\Program Files\Oracle\VirtualBox Guest Additions>VBoxControl.exe guestproperty get /MyData/VMname
Oracle VM VirtualBox Guest Additions Command Line Management Interface Version 4.1.14
(C) 2008-2012 Oracle Corporation
All rights reserved.
Value: Windows 7 (x64)

The GuestProperty API is pretty powerful, so for the interested, get more info in the User Manual.

- FB 

Comments:

Post a Comment:
Comments are closed for this entry.
About

Fat Bloke

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today