Programmatically detecting host information from inside the guest under Virtual PC and Virtual Server

Programmatically detecting host information from inside the guest under Virtual PC and Virtual Server

Rate This
  • Comments 3

At various times it is convenient to be able to identify the host computer from inside of a virtual machine in a programatic fashion (e.g. When you are deploying a virtual machine or running an automated process).  To help in these scenarios both Virtual Server and Virtual PC 2004 SP1 will populate the virtual machines registry with information on the name of the host computer, and the name assigned to the virtual machine under Virtual PC or Virtual Server.

This information is only available on virtual machines running Windows 95 through Windows Server 2003 with Virtual Machine Additions installed - and is stored in [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters].

You can retrieve this information using the following VBScript:

' || Script begins
'
' Setup constant

const HKEY_LOCAL_MACHINE = &H80000002

' Setup registry object (this is a single line)
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

' Set the key path and values to look at
strKeyPath = "SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters"
strValueName1 = "HostName"
strValueName2 = "VirtualMachineName"

' Get the values from the registry
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName1, dwValue1
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName2, dwValue2

' Display the results
WScript.Echo "The virtual machines hosts name is: " & dwValue1
WScript.Echo "The virtual machines name is: " & dwValue2
'
' || Script ends

Cheers,
Ben

 

Leave a Comment
  • Please add 8 and 2 and type the answer here:
  • Post
  • Very nice. People have been asking for this in the NG for ages.

    Scott
  • So when will Microsoft document the way the additions can talk to the host? I am not on about complicated stuff, but simple things like the information above, or the time. Presumably it is just some sequence of illegal instructions or I/O.

    My goal is to be able to write additions for some embedded environments as well as Linux.
  • I'd second that of the Anonymous Coward. The "backdoor" of the VMware has been opened on http://chitchat.at.infoseek.co.jp/vmware/backdoor.html though I can't tell if that's been done by "leaking" information of reverse engineering. Anyway, it already lead to VMware tools for QNX (http://projects.qnxzone.com/projects/qnx-vmware/).
    I'd like to hack a pendant together for VPC, since running QNX in Windows was my main cause for buying VPC, but I'm lacking the reverse engineering skills.
Page 1 of 1 (3 items)