posts - 4238, comments - 3946, trackbacks - 370

My Links

News



Subscribe Subscribe

image image image





This is my personal weblog. These postings are provided 'AS IS' with no warranties, and confer no rights. The views expressed on this weblog are mine alone and do not necessarily reflect the views of my employer.

Licenza Creative Commons

Tag Cloud

Archives

Post Categories

Determinare se si sta girando su Virtual PC o Virtual Server

Un po' di tempo fa parlando di Virus che non vanno su VPC mi ero chiesto come facessero... Bene, ecco la risposta:

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< /FONT >

' 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

 

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

Technorati Tags: ,

Print | posted on venerdì 28 gennaio 2005 22:07 |

Feedback

Gravatar

# Determinare se si sta girando in una macchina virtuale #2

15/03/2005 19:34 | Lorenzo Barbieri @ UGIblogs!
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET