Hyper-V Program Manager
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?
VirtualMachineDetect uses some more techniques to detect VirtualPc. You can find it in securityresearch.in/.../virtualmachinedetect-v-2-1-1-beta-is-out.
Hi Ben,
This has been working fine up until 'Windows Surface Pro'. Now 'Windows Surface Pro' also returns 'Manufacturer' value from Win32_BaseBoard as 'Microsoft Corporation'. So do you have an official Microsoft link that explains how to detect if we are running under a virtual machine?
Thanks.