Hyper-V Program Manager
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 constantconst 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 atstrKeyPath = "SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters"strValueName1 = "HostName"strValueName2 = "VirtualMachineName"
' Get the values from the registryoReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName1, dwValue1oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName2, dwValue2
' Display the resultsWScript.Echo "The virtual machines hosts name is: " & dwValue1 WScript.Echo "The virtual machines name is: " & dwValue2'' || Script ends
Cheers,Ben