-- Ben Armstrong, Virtualization Program Manager
Talking about core virtualization at Microsoft (Hyper-V, Virtual PC and Virtual Server).
From time to time it is handy to be able to detect that you are running inside of a virtual machine (for instance - you may have maintenance scripts that you want to run on all of your computers - but have them behave differently inside of your virtual machines). The easiest way to detect that you are inside of a virtual machine is by using 'hardware fingerprinting' - where you look for hardware that is always present inside of a given virtual machine. In the case of Microsoft virtual machines - a clear indicator is if the motherboard is made by Microsoft:
Dim Manufacturer
strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BaseBoard")
For Each objItem in colItems Manufacturer = objItem.ManufacturerNext
if Manufacturer = "Microsoft Corporation" then wscript.echo "In Microsoft virtual machine"else wscript.echo "Not in Microsoft virtual machine"end if
The above script uses WMI to find out the motherboard manufacturer information. If the motherboard is made by "Microsoft Corporation" then you are inside of one of our virtual machines. Now to preemptively answer some questions that I can see people having about this:
Anyway - enjoy the script :-)
Cheers,Ben
Does this work approach work w/ Hyper-V R2?