'---------------------------------------------------------------------------------------
' Module      : mSMBIOS_VMDetect
' DateTime    : 10/26/2009 22:31
' Author      : Cobein
' Mail        : cobein27@hotmail.com
' WebPage     : http://www.advancevb.com.ar
' Purpose     : Simple BIOS VM dettection
' Usage       : At your own risk
' Requirements: None
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce
'               or publish this code on any web site,
'               online service, or distribute as source
'               on any media without express permission.
'
' Reference   : http://msdn.microsoft.com/en-us/library/ms724259(VS.85).aspx
'
' Notes       : The select case can be epanded to add more detections, read the
'               documetation to make sure this API is available in your system otherwise
'               you may want to use some OS version detection routine.
'
' History     : 10/26/2009 First Cut....................................................
'---------------------------------------------------------------------------------------
Option Explicit

Private Declare Function GetSystemFirmwareTable Lib "kernel32" ( _
    ByVal FirmwareTableProviderSignature As Long, _
    ByVal FirmwareTableID As Long, _
    ByVal pFirmwareTableBuffer As Long, _
    ByVal BufferSize As Long) As Long

Public Function IsVMPresent() As Boolean
    Dim lSize       As Long
    Dim bvTable()   As Byte
    Dim sData       As String

    lSize = GetSystemFirmwareTable(&H4649524D, &HC0000, 0, 0)
    If lSize Then
        ReDim bvTable(lSize - 1)
        If GetSystemFirmwareTable(&H4649524D, &HC0000, VarPtr(bvTable(0)), lSize) Then
            sData = UCase(StrConv(bvTable, vbUnicode))
            '// This 'Select Case' can be expanded to detect different VM systems
            Select Case True
                Case sData Like "*VIRTUALBOX*": IsVMPresent = True
            End Select
        End If
    End If
End Function