Sunday, November 1, 2009

Am I a VMWare Guest Machine or Not?

VBScript Version
Function IsVmWareClient()
Dim objWMIService, colBIOS, objBIOS, retval
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colBIOS = objWMIService.ExecQuery("Select SerialNumber from Win32_BIOS")
For each objBIOS in colBIOS
If Left(objBIOS.SerialNumber, 6) = "VMware" Then
retval = True
Exit For
End If
Next
IsVmWareClient = retval
End Function

' test

If IsVmWareClient() Then
wscript.echo "yes - this is a vmware guest machine"
Else
wscript.echo "not a vmware guest machine"
End If

KiXtart Version

Function IsVmWareClient()
Dim $wmiService, $colBIOS, $objBIOS, $retval
$wmiService = GetObject("winmgmts:\\.\root\CIMV2")
$colBIOS = $wmiService.ExecQuery("select SerialNumber from Win32_BIOS")
For Each $objBIOS in $colBIOS
If Left($objBIOS.SerialNumber, 6) = "VMware"
$retval = 1
EndIf
Next
$IsVmWareClient = $retval
EndFunction

; test

If IsVmWareClient()
? "yes - this is a vmware guest machine"
Else
? "not a vmware guest machine"
EndIf

No comments:

Post a Comment