Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
November 8, 2006
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 offif {%1}=={} @echo Syntax: isVirtual VorP&goto :EOFif exist "%TEMP%isVirtual.vbs" goto :[email protected] = ".">"%TEMP%isVirtual.vbs"@echo.Set objWMIService = GetObject("winmgmts:" _>>"%TEMP%isVirtual.vbs"@echo. ^& "{impersonationLevel=impersonate}!\" ^& strComputer ^& "rootcimv2")>>"%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.Next>>"%TEMP%isVirtual.vbs"@echo.if lcase(left(strType,6))="vmware" then>>"%TEMP%isVirtual.vbs"@echo. Wscript.Echo "V">>"%TEMP%isVirtual.vbs"@echo.else>>"%TEMP%isVirtual.vbs"@echo. Wscript.Echo "P">>"%TEMP%isVirtual.vbs"@echo.end if>>"%TEMP%isVirtual.vbs":DOITfor /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%isVirtual.vbs"') do set %1=%%a
You May Also Like