Is It Possible To Query The Host's Name From Within A Guest?

Discussions about using Windows guests in VirtualBox.
Post Reply
saberman
Posts: 292
Joined: 21. Dec 2009, 00:32
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, 7, 8.1, 10

Is It Possible To Query The Host's Name From Within A Guest?

Post by saberman »

Host: Windows 8.1 Pro x64
Guest: Windows 7 Ultimate x64

I have a development/testing environment where a VM may be moved from one host to another. Each of the hosts have the same set of folders. I want to be able to dynamically map a couple of the host's folders when a user signs into a VM. For example, consider the following folder structure on the host:
V:\VirtualBox (Shared as VirtualBox)
V:\VirtualBox\Data1
V:\VirtualBox\Data2
Host: Host1
When a user logs into the VM I want to map
G ==> \\<hostname>\VirtualBox\Data1
H ==> \\<hostname>\VirtualBox\Data2
I can used shared folders for this as they do provide full Windows support.
If I can grab the host's name I can write a little utility that will be called from a login script to do the mapping.
noteirak
Site Moderator
Posts: 5231
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by noteirak »

You can't query the host name from virtualbox itself, no.
What is possible on the other hand would be to set a custom guestproperty from the host and then get this back from the guest.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
saberman
Posts: 292
Joined: 21. Dec 2009, 00:32
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, 7, 8.1, 10

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by saberman »

>set a custom guestproperty from the host and then get this back from the guest.
Is there a simple way to do that?

If not I think I will setup a shared folder for the purpase of having a cmd file in a folder called Startup that will do the mapping. The login script in the guest would run the cmd file. Each host would have the same file folder and cmd file but with the host's name in the cmd file. It will waste a drive letter as the folder will have to be statically mapped in the guest.
ChipMcK
Volunteer
Posts: 1095
Joined: 20. May 2009, 02:17
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, OSX
Location: U S of A

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by ChipMcK »

saberman wrote:>set a custom guestproperty from the host and then get this back from the guest.
Is there a simple way to do that?
check out HOWTO: Use Guest Properties

google search guestproperty site:forums.virtualbox.org
rpmurray
Volunteer
Posts: 918
Joined: 3. Mar 2009, 00:29
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 7, Mac OS X (various flavors)
Location: Between Heaven and Hell

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by rpmurray »

ChipMcK wrote:check out HOWTO: Use Guest Properties
I'm assuming this only works if you have Guest Additions installed in the guest?

Edit: Yes, that's the case. From the manual:
4.6 Guest properties. Starting with version 2.1, VirtualBox allows for requesting certain properties from a running guest, provided that the VirtualBox Guest Additions are installed and the VM is running.
saberman
Posts: 292
Joined: 21. Dec 2009, 00:32
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, 7, 8.1, 10

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by saberman »

ChipMcK wrote:
saberman wrote:>set a custom guestproperty from the host and then get this back from the guest.
Is there a simple way to do that?
check out HOWTO: Use Guest Properties

google search guestproperty site:forums.virtualbox.org
The link has:
On the Host the properties are accessed through VBoxManage command with the following qualifiers:guestproperty get <vmname>|<uuid> <property> [-verbose]
guestproperty set <vmname>|<uuid> <property> [<value> [-flags <flags>]]
guestproperty enumerate <vmname>|<uuid> [-patterns <patterns>]
and on the Guest with the corresponding VBoxControl commands
guestproperty get <property> [-verbose]
guestproperty set <property> [<value> [-flags <flags>]]
guestproperty enumerate [-patterns <patterns>]

I am sure that is very meaningful to someone working with the VitrualBox SDK but it is meaningless to me. I need to be able to set a property that is passed to all VMs on the host. I also do not see how I can retieve the property in the guest programatically -- they appear to be command line commands.

I will try the shared folder with a script approach. At least I understand that.
ChipMcK
Volunteer
Posts: 1095
Joined: 20. May 2009, 02:17
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, OSX
Location: U S of A

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by ChipMcK »

saberman wrote: I am sure that is very meaningful to someone working with the VitrualBox SDK but it is meaningless to me. I need to be able to set a property that is passed to all VMs on the host. I also do not see how I can retieve the property in the guest programatically -- they appear to be command line commands.
I do not have the SDK installed and the commands work without errors. Yes, you will need to develop script files using the commands, just as you will for the 'shqred folders' approach.
saberman
Posts: 292
Joined: 21. Dec 2009, 00:32
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, 7, 8.1, 10

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by saberman »

>Yes, you will need to develop script files using the commands
Any example of having the script on the host side run everytime a VM is started?
ChipMcK
Volunteer
Posts: 1095
Joined: 20. May 2009, 02:17
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, OSX
Location: U S of A

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by ChipMcK »

you are joking, yes?

You might try reading the * manual.

8.30. VBoxManage guestproperty

and

4.6. Guest properties

Life is easier if you RTFM
saberman
Posts: 292
Joined: 21. Dec 2009, 00:32
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, 7, 8.1, 10

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by saberman »

>You might try reading the * manual.
I did before I posted. Now please point me to the part that explains how to trigger the VBoxManage guestproperty command automatically after VirtualBox starts a guest VM sending the host's name as the value of the property.
ChipMcK
Volunteer
Posts: 1095
Joined: 20. May 2009, 02:17
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, OSX
Location: U S of A

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by ChipMcK »

I did not realize that English is not your native language
set <vm> <property> [<value> [--flags <flags>]]: This allows you to set a guest property by specifying the key and value. If <value> is omitted, the property is deleted. With --flags you can optionally specify additional behavior (you can combine several by separating them with commas):

TRANSIENT: the value will not be stored with the VM data when the VM exits;

TRANSRESET: the value will be deleted as soon as the VM restarts and/or exits;
TRANSIENT: the value will not be stored with the VM data when the VM exits; means that the VBoxManage guestproperty set command needs be issued only once. BTW, VBox does not need to be active for my V4.3.10

Comprehend?

edited: substitute "only" in place of "but"
Last edited by ChipMcK on 28. Apr 2014, 12:49, edited 1 time in total.
saberman
Posts: 292
Joined: 21. Dec 2009, 00:32
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, 7, 8.1, 10

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by saberman »

>Comprehend?
No. Here is the scenario:
1. Copy the environment -- everything associated with VirtualBox -- to another host.
2. Click on a shortcut to start a VM.
3. User logs into the VM.

As I understand it, a request from the host to set a property has to be made when a VM is running. Exactly where do I put a script to set a property with the host's name that will execute automatically immediately after the VM starts but before the first user logins into the VM?
ChipMcK
Volunteer
Posts: 1095
Joined: 20. May 2009, 02:17
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, OSX
Location: U S of A

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by ChipMcK »

saberman wrote:>Comprehend?
No. Here is the scenario:
1. Copy the environment -- everything associated with VirtualBox -- to another host.
2. Click on a shortcut to start a VM.
3. User logs into the VM.

As I understand it, a request from the host to set a property has to be made when a VM is running. Exactly where do I put a script to set a property with the host's name that will execute automatically immediately after the VM starts but before the first user logins into the VM?
The VBoxManage guestproperty set command is issued during the previous week, when you decide what key and its value for your VMs.
And the target VMs need not be active at the moment that VBoxManage guestproperty set command is issued

.
saberman
Posts: 292
Joined: 21. Dec 2009, 00:32
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, 7, 8.1, 10

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by saberman »

>during the previous week
This is a development environment. I shift hosts at least once a day and sometimes multiple times a day. The porocess has to be fully automated including inserting the name of the host in the guestproperty command.

>target VMs need not be active at the moment that VBoxManage guestproperty set command is issued
From the manual:
The “guestproperty” commands allow you to get or set properties of a running virtual machine.

I think the shared folder approach is easier and safer.
ChipMcK
Volunteer
Posts: 1095
Joined: 20. May 2009, 02:17
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, OSX
Location: U S of A

Re: Is It Possible To Query The Host's Name From Within A Gu

Post by ChipMcK »

saberman wrote:>target VMs need not be active at the moment that VBoxManage guestproperty set command is issued
From the manual:
The “guestproperty” commands allow you to get or set properties of a running virtual machine.
Not on my v4.3.10. That VM need not be active. It setting becomes part of the VM definition, unless
set <vm> <property> [<value> [--flags <flags>]]: This allows you to set a guest property by specifying the key and value. If <value> is omitted, the property is deleted. With --flags you can optionally specify additional behavior (you can combine several by separating them with commas):

TRANSIENT: the value will not be stored with the VM data when the VM exits;

TRANSRESET: the value will be deleted as soon as the VM restarts and/or exits;
Post Reply