How can I detect (.NET or Win32) if my application is running in a virtual machine?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- the application was unable to start correctly 0xc0
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
This is what I use:
Edit 2014-12-02: Updated code so that it no longer detects a Microsoft Surface Pro as a VM. Thanks to Erik Funkenbusch for pointing this out.
Edit 2017-06-29: Updated code so that it also checks the value of the
HypervisorPresent
property.Edit 2018-02-05: removed check for the
HypervisorPresent
property since it's incorrect. This property could return true if running on the host O/S on a hyper-V server.For Lower level Tests I recommend looking at ScoopyNG [1]. It is a collection of known low-level, well working vm detection methods, albeit being a little dated.
If you really want to rely on other things, like installed tools (VM* Additions) , these are much easier to "fake".
This [2] Blog Post also has a pretty nice overview, from low level asm stuff, checking for specific DLLs, filepaths and registry keys to check.
[1] http://trapkit.de/research/vmm/scoopyng/index.html
[2] http://securitykitten.github.io/vm-checking-and-detecting/
this C++ code will detect Vmware Products such as express,esx,fusion or workstation
Jay Abuzi showed the solution in powershell. Here's the same as a c# function:
This C function will detect VM Guest OS: (Tested on Windows, compiled with Visual Studio)