Virtual computing isn’t all that exotic anymore. These days, it’s a big part of how many people do their work....
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
To that end, it helps to know how to deal with scenarios that used to be unusual, but are now common, such as detecting whether or not you’re running a particular program inside a virtual machine.
Why do this? For one, you might not want certain programs running in a virtual environment since they may not perform the way you’d expect. Additionally, it could be a good idea to warn users that they might need to install support for certain kinds of virtual hardware before proceeding.
One quick way to detect whether or not you’re running Windows in a virtual machine is by using a batch file to pull system information with the WMIC utility. This command-line tool is a front-end for the Windows Management Instrumentation (WMI) subsystem, from which you can harvest a whole slew of low-level information about a given system.
For instance, try this experiment. Fire up a Windows computer that’s running a virtual machine application of some kind -- be it Microsoft Hyper-V, Oracle VM VirtualBox or something from VMware -- and type the following command in both the virtual machine and host OS:
wmic computersystem get model /format:csv
Compare the results. On the host machine, you should get something like this:
<systemname>, Dell XPS420
On the virtual machine, you’ll see something like this:
Virtual machines tend to report the machine model as the name of the virtualization application, which makes it relatively easy to identify whether or not you’re running a virtual machine without any terribly sophisticated programming.
Joeware.net provides a batch file to do this kind of processing automatically. The script has built-in strings for both VMware virtualization and Hyper-V. It’s simple enough that you can easily add other virtualization technologies like VirtualBox, as long as you know what strings they return for the machine model.
If you’re not using conventional batch files anymore, the same data can be retrieved in Windows PowerShell using the Get-WmiObject command (also abbreviated as gwmi):
Get-WmiObject Win32_Computersystem model
For more concise output you can use:
Get-WmiObject Win32_Computersystem | Format-List model
The manufacturer attribute can also be used in conjunction with model to determine if you’re in a virtual machine. VirtualBox, for instance, returns a manufacturer of “innotek GmbH” (the original creators of VirtualBox). Such details can easily be harvested from various virtual machines and checked against by whatever script you’re using.
You can follow SearchWindowsServer.com on Twitter @WindowsTT.
ABOUT THE AUTHOR
Serdar Yegulalp has been writing about computers and information technology for more than 15 years for a variety of publications, including InformationWeek and Windows Magazine.