Wednesday, May 19, 2010

Detect running inside a Virtual Machine

In December 2008, I wrote a tool to detect if we are running inside a Virtual Machine, this small application called DetectVM works fine for a several months until I received a few complains about it: not working on x64 systems and don't detect VMware ESX 4.0 vSphere.

Today I rewrite the whole application for scratch on Visual Studio.NET. The new version DetectVM 2.0 works on x86 and x64 systems and detect ESX 4.0 vSphere.

Detect VM 2.0 detect Virtual Machines running on Microsoft Virtual Server and Hyper-V, VMware and Citrix XenServer.

When you run DetectVM 2.0, the application return a code so we can run on silent mode (use /quiet or /q parameter) on a batch file.

Below is a script example:

---- Start Script ----

@ECHO OFF
DetectVM /QUIET
IF ERRORLEVEL 100 GOTO ErrorVM
IF ERRORLEVEL 3 GOTO Xen
IF ERRORLEVEL 2 GOTO VMware
IF ERRORLEVEL 1 GOTO Microsoft

REM No Virtual Machine
ECHO Not running inside a Virtual Machine
GOTO End

:Microsoft
REM Microsoft
ECHO Running Inside a Microsoft Virtual Machine
GOTO End

:VMware
REM VMware
ECHO Running Inside a VMware Virtual Machine
GOTO End

:Xen
REM Citrix XenServer
ECHO Running Inside a Citrix XenServer Virtual Machine
GOTO End

ErrorVM
ECHO Error Detecting Virtual Machine
:End

---- End Script ----

You can download DetectVM for FREE, the script and source code from
http://ctxadmtools.musumeci.com.ar

No comments: