VMware Communities > VMTN > Archives > Desktop and Server Archives > VMware Workstation Archives > Discussions
This thread is archived
1 Replies Last post: Dec 19, 2003 9:31 AM by frond

How to detect VMWare guest machine?

Dec 19, 2003 9:08 AM

Click to view tly53's profile Lurker tly53 7 posts since
Sep 24, 2003
I am writing a program to run on both Host machine and
VMWare guest machine and I need to run different method depends on Host machine or guest machine.
So I am wondering is there a way to differentiate or to check that if you're in a guest machine or host machine.

Any help will be appreciated very much
Re: How to detect VMWare guest machine? Dec 19, 2003 9:31 AM
Click to view frond's profile Novice frond 66 posts since
Oct 6, 2003
We do this with a quick and dirty VBS script. We just run it within a batch file and check the error level that's returned.

We've tested it under ESX 1.5.2 and 2.0.1, but I assume it would work just fine in the workstation version as well.

' *******************************************************************
' Filename: isVMware.vbs
'
' Dependencies: none
'
' Queries WMI for the Manufacturer value. If it contains "VMware," the
' script returns errorlevel=1. Otherwise the script returns
' errorlevel=0
'
' *******************************************************************

set objNet = WScript.CreateObject("WScript.Network")

strWinMgt = "winmgmts://" & objNet.ComputerName

set DeviceSet = GetObject(strWinMgt).ExecQuery("select * from Win32_ComputerSystem")

i=0

for each Device in DeviceSet
if Instr(1, Device.Manufacturer, "VMware", 1) then
i=i+1
end if
next

WScript.Quit(i)
Actions