Results 1 to 7 of 7

Thread: Detect if Running in a Virtual Machine

  1. #1

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,663

    Question Detect if Running in a Virtual Machine

    Hi,

    I've had a search around to tips and tricks, but nothing seems to work properly other than c++ : One example can be found here: http://kb.vmware.com/selfservice/mic...rnalId=1009458

    Is there a way of perhaps converting this to VB or maybe through ASM to VB?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Detect if Running in a Virtual Machine

    The advice at Detecting Microsoft virtual machines suggests WMI.

    I don't care much for WMI since it is not meant to be used in applications and may be disabled or even uninstalled. An alternative is to call the GetSystemFirmwareTable function yourself.

    However as it says there this function was only made available within the last decade:

    Minimum supported client Windows Vista, Windows XP Professional x64 Edition

    Minimum supported server Windows Server 2008, Windows Server 2003 with SP1
    So the dead Windows XP is more or less crippled for this.


    Though that blog post says to check BaseBoardManufacturer I find SystemManufacturer to be far more reliable. Of course now there are those "Microsoft Dufus" and "Dufus Pro" tabletoid systems so all bets are off.

    Even when these return non-null values though you still have to check them to see if they look like a VM vendor's product.


    Demo code attached.


    Name:  sshot.png
Views: 2312
Size:  5.1 KB

    Win7 running in MS Virtual PC 6
    Attached Files Attached Files

  3. #3
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,625

    Re: Detect if Running in a Virtual Machine

    That's just for MS virtual machines thought right? Every VM has it's own way of being detected, and they're all unreliable.
    It might be better to look at the underlying issue that you're trying to address, and consider that there might be a better way to accomplish the end result. If you're doing something so sophisticated that you absolutely need to know (which is almost never in VB6) then having a small support DLL written in C++ to try to run through the tricks for other VMs shouldn't be an issue.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Detect if Running in a Virtual Machine

    I think the point is that there just isn't any simple absolute test to prove whether you are running in a VM or on real hardware. Everything you can do will have to rely on profiling of one sort or another.

    They also seem pretty clear that cases justfying the effort are hard to imagine. The only one they thought of there could be handled very easily with a setting in an INI file, the registry, etc. to mark a machine (VM or real) as "don't run maintenance script X."

  5. #5
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,207

    Re: Detect if Running in a Virtual Machine

    I'd think that the already proposed way (looking up some Hardware-Descriptions per WMI),
    isn't all that bad.

    Code:
    Private Sub Form_Load()
      Dim oItem
      With GetObject("winmgmts:\\.\root\cimv2")
        
        For Each oItem In .ExecQuery("Select * from Win32_ComputerSystem") 'found at stackoverflow
          Debug.Print oItem.Model, CBool(InStr(1, oItem.Model, "Virtual", vbTextCompare))
        Next
        
        'alternatively a look at the graphics-card could be useful as well ...
        For Each oItem In .ExecQuery("Select * from Win32_VideoController")
          Debug.Print oItem.Caption, CBool(InStr(1, oItem.Caption, "VMWare", vbTextCompare))
        Next
        
      End With
    End Sub
    For a VMWare-guest one will get from the above:
    Code:
    VMware Virtual Platform     True
    VMware SVGA 3D              True
    When the check over the graphics-adapter-devicecaption is used, one will need
    to add some additional Instr-Tests for what the MS-VHost - and Oracle VBox will
    spit out (have none of those VMs here to test that myself).

    Olaf

  6. #6
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,625

    Re: Detect if Running in a Virtual Machine

    Another possibility- anyone installing your program in a VM is almost certainly aware of that fact; you could just throw up a warning during setup that asks 'Are You Using XPMode/MS Virtual Machine, VMWare, VirtualBox, etc/If you are and don't say yes app won't work'

  7. #7
    Addicted Member jg.sa's Avatar
    Join Date
    Nov 2017
    Location
    South Australia ( SA )
    Posts
    196

    Re: Detect if Running in a Virtual Machine

    G'Day Some
    If you are using VMware, check if tools installed

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width