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.
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.
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."
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).
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'