Skip navigation

Q. How can a batch determine if it running on a VMWare Virtual server or on a Physical server?

I have scripted isVirtual.bat to determine if a batch is running on a VMWare Virtual server or on a Physical server.

The syntax for using isVirtual.bat is:

\[call\] isVirtual VorP

Where VorP is a call directed environment variable that will contain a V or a P.

isVirtual.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: isVirtual VorP&goto :EOF
if exist "%TEMP%\isVirtual.vbs" goto :DOIT
@echo.strComputer = ".">"%TEMP%\isVirtual.vbs"
@echo.Set objWMIService = GetObject("winmgmts:" _>>"%TEMP%\isVirtual.vbs"
@echo.    ^& "\{impersonationLevel=impersonate\}!\\" ^& strComputer ^& "\root\cimv2")>>"%TEMP%\isVirtual.vbs"
@echo.Set colSettings = objWMIService.ExecQuery _>>"%TEMP%\isVirtual.vbs"
@echo.    ("Select * from Win32_ComputerSystem")>>"%TEMP%\isVirtual.vbs"
@echo.For Each objComputer in colSettings >>"%TEMP%\isVirtual.vbs"
@echo.    strType = objComputer.Manufacturer>>"%TEMP%\isVirtual.vbs"
@echo.if lcase(left(strType,6))="vmware" then>>"%TEMP%\isVirtual.vbs"
@echo.	  Wscript.Echo "V">>"%TEMP%\isVirtual.vbs"
@echo.    Wscript.Echo "P">>"%TEMP%\isVirtual.vbs"
@echo.end if>>"%TEMP%\isVirtual.vbs"
for /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%\isVirtual.vbs"') do set %1=%%a

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.