Determine when running in a virtual machine

后端 未结 10 453
遇见更好的自我
遇见更好的自我 2020-12-12 11:39

Is there an official way for an application to determine if it is running in VMWare or Virtual PC (or whatever Microsoft is calling it now)? The code I have seen i

相关标签:
10条回答
  • 2020-12-12 11:53

    This thread on the SysInternals forums has a couple of answers (in Delphi, of course), including a single IsVM function. I've tested on XP and Win2003 hosted on both XP and Vista in VMWare with good results.

    0 讨论(0)
  • 2020-12-12 11:56

    I wrote a series of articles last year on this, with source code. VMware and Wine detection are here. Virtual PC is here. All three of these have pretty iron-clad detection because there are documented callbacks to the hypervisor (in the case of Wine, an extension to a standard DLL). I put up an untested VirtualBox detector (don't have it installed to test with) in the comment section. Parallels might be detectable using a callback also but I don't have it installed. The link for the documentation (which is poor since it's from a security researcher focusing on exploits) but located here if you have it installed and are interested. There's also a PPT here that has some information on detecting Sandbox, Bochs, and Xen. Not a lot of code in it but it might give you a starting point if you have to detect those.

    0 讨论(0)
  • 2020-12-12 11:56

    Code Project shows a way to Detect if your program is running inside a Virtual Machine that goes in much detail on how to accomplish it to give a good understanding

    0 讨论(0)
  • 2020-12-12 12:02

    There is a WMI way posted here: http://blogs.msdn.com/virtual_pc_guy/archive/2005/10/27/484479.aspx

    I've double checked in an XP image running on Virtual PC, and the value they're testing for is still the same. I won't guarantee what other VMs return here, though...

    I've actually got a Delphi program I wrote a couple of years ago to get a list of and change the default printer using WMI, without requiring 3rd party components or anything like that. In case you're not used to working with WMI from Delphi, I can send you a copy so you have something to work off (it's not necessarily Unicode-compatible, though, but it shouldn't be too hard for me to upgrade it if need be).

    0 讨论(0)
  • 2020-12-12 12:04

    To determine the machine is physical or VM

    dmidecode | egrep -i 'manufacturer|product'
    

    If the dmidecode command not found install the respective rpm.

    This is tested under EXSI, VMWARE and hyperv machines.

    0 讨论(0)
  • 2020-12-12 12:07
    dmidecode -s system-product-name
    

    Tested on VirtualBox, result:

    Virtualbox
    
    0 讨论(0)
提交回复
热议问题