Passing data between the VirtualBox Host and the Guest
By Fat Bloke on Apr 13, 2012
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.
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]
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.