Search for a string in command line output
Try this:
systeminfo | findstr /I /B /C:"system model" | findstr /I "virtual"if %errorlevel% == 0 ( echo virtual machine) else ( echo real machine)
I've tested in on a real and virtual system and it works fine on WinXp and Win7. Note that the system model
string is only used in English Windows versions. Windows versions in other languages will use a different names.