Page 1 of 1 1
Topic Options
#189234 - 2008-08-22 03:06 PM Detect Virtual Machine
Verne Offline
Fresh Scripter

Registered: 2006-02-13
Posts: 19
Hi. I've been looking for a Kix script which will detect if the client is running in a virtual environment. So far I've only been able to find this http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=110606#Post110606

The post is 5 years old now and I was wondering if this is the best way to do it? I've found some examples at this web site http://talhatariq.wordpress.com/2006/05/14/detecting-virtualization-2/ which suggest some other ways of doing it. I could probably have a go at converting them to Kix but if someone has already done it I don't want to reinvent the wheel.

I want to put this functionality into our main logon script so if it detects it is running in a virtual environment it does not install certain software.

Thanks.

Top
#189236 - 2008-08-22 03:54 PM Re: Detect Virtual Machine [Re: Verne]
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 950
Loc: Stockholm, Sweden.
to keep it short, you could always check for let's say,nic, chipset / something in the file structure etc.
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#189237 - 2008-08-22 04:25 PM Re: Detect Virtual Machine [Re: Björn]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
This works for me.

 Code:
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_BaseBoard ")

For Each $wmiObj in $wmiColl
	If $wmiObj.Manufacturer = "Microsoft Corporation"
		?$wmiObj.Manufacturer
		? "Virtual machine"
	Else
		?$wmiObj.Manufacturer
		? "Not a virtual machine"
	EndIf		
Next

Sleep 5
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#189238 - 2008-08-22 07:08 PM Re: Detect Virtual Machine [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4291
Loc: New Jersey
Mart

That doesn't work for me when I run on my Vista system on ESX 3.5.

When I run my HWInfo() UDF, it returns the following:
 Code:
   Server Information for VISTAADMIN
=====================================
 0 - System Manufacturer:    VMware, Inc.
 1 - System Model:           VMware Virtual Platform
 2 - System Serial Number:   VMware-56 4d e5 19 96 73 af 12-bd 3d 26 91 38 61 5b 74
 3 - BIOS Info:              PTLTD  - 6040000 [6.00]
These are the result of the following WMI queries:
 Code:
Win32_ComputerSystem  /  Manufacturer
Win32_ComputerSystem  /  Model
Win32_BIOS  /  SerialNumber
Win32_BIOS  /  Version

You can get the HWInfo UDF from my web site, or just make the needed WMIQuery call - like
 Code:
WMIQuery('Model', 'Win32_ComputerSystem', $_Target, '', '', '')

WMIQuery is available here or on my site.

I've run this under ESX 2.x and 3.x with good reliability. Maybe someone can report the results under MS Virtual Server, or other VMWare platforms.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#189244 - 2008-08-24 12:24 PM Re: Detect Virtual Machine [Re: Glenn Barnas]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4642
Loc: The Netherlands
Yeah, I know. I do not have any VMWare so couldn't test. The original poster also did not specify what VM app he is using so I tested on my own system that only has MS virtual PC 2007 and not VMWare.

Maybe the origin al poster can tell us what VM app he is using.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#189276 - 2008-08-26 02:06 AM Re: Detect Virtual Machine [Re: Mart]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
Actually checking a service would probably be the best method. There are now also a few types of virtual machines VMware and Microsoft are maybe the biggest but there are others.

Here is a script I wrote to detect VMware a few years ago. I would probable change the code now days a bit, but you get the idea.

 Code:
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')

Dim $VMRunning
$VMRunning = WithinVMware()
If $VMRunning = 1
  'Logon is running under a VMware session.' ?
Else
  'Logon is NOT running under a VMware session.' ?
EndIf

Function WithinVMware()
  Dim $InWMware
  Dim $VMTools, $VMProcess, $Key
  $InWMware = 0
  Select
    Case 1 = KeyExist('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\VMip.exe')
      $InWMware = 1
    Case 1 = KeyExist('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\VMwareTray.exe')
      $InWMware = 1
    Case 1
  EndSelect
  $WithinVMware = $InWMware
EndFunction

Top
#189331 - 2008-08-28 06:40 PM Re: Detect Virtual Machine [Re: NTDOC]
Verne Offline
Fresh Scripter

Registered: 2006-02-13
Posts: 19
Thanks for all the replies.

We are running VMware, Microsoft Virtual Server and Microsoft Virtual PC 2007. If I combine the two ways for Microsoft and VMware posted here it should do the job.

Thanks again.

Top
#189335 - 2008-08-29 12:36 AM Re: Detect Virtual Machine [Re: Verne]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
Great. When you do get it done and tested please post your completed code so that others can benefit from it as well.

Thanks

Top
#189348 - 2008-08-29 11:46 PM Re: Detect Virtual Machine [Re: NTDOC]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
looking for service?
doc, you looked for tray app. how is that a service? ;\)

the board/system method is quite clever, imo.
but indeed it isn't full proof as there are so many products.
on the other hand, which check is?
we all know kixtart needs to be updated to understand the windows versions and CPU versions as they change.
and even my newest installation of SBS says, it's running on PIII when it's actually running on core 2 duo.

so, imo, the easiest and most suitable way would be to detect the system manufacturer
_________________________
!

download KiXnet

Top
#189375 - 2008-09-02 11:54 PM Re: Detect Virtual Machine [Re: Lonkero]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
I said checking a service WOULD probably be best, not that I WAS checking it.
Top
#189377 - 2008-09-03 01:11 AM Re: Detect Virtual Machine [Re: NTDOC]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
true.
_________________________
!

download KiXnet

Top
#189412 - 2008-09-04 12:43 AM Re: Detect Virtual Machine [Re: Lonkero]
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 950
Loc: Stockholm, Sweden.
I still don't get it. why are you looking for applications, when returning the nic-properties is suffient?
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#189517 - 2008-09-07 01:53 PM Re: Detect Virtual Machine [Re: Björn]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
what you mean with nic-properties?
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 156 anonymous users online.
Newest Members
diefnet, Arogya, gkustra, emnipetro, Hirze
17644 Registered Users

Generated in 0.038 seconds in which 0.011 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org