Question

Maybe this is a cross-system issue, and maybe not. But I am just working on Mac OS X, therefore I focus on Cocoa.

As my title described, can I detect whether my application is run in an virtual environment programmatically? (not only vmware, but also some other virtual environment like Sandboxie in Windows)

Was it helpful?

Solution

There won't be any native Cocoa API's to specifically ask if you are running in a virtual machine vs real hardware.

However, if you know the potential environments you are running under you should be able to use IOKit to query the hardware of the virtual machine.

Virtual Machines will have considerably different hardware than a real Mac so you should be able to detect a real Mac vs a VM based on hardware configuration.

I can not give you any direct code, however, there is a section on Apple's site that discusses accessing hardware with IOKit in general:

https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_IOKitLib_API/AH_IOKitLib_API.html

IOKit is an advanced subject so if you do not have a lot of experience with the lower-level APIs you may find it a bit confusing as compared to Cocoa.

OTHER TIPS

Maybe you can cross-compile virt-what and make use of it.

In addition to I/O Kit you could use C POSIX functions. Check the man pages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top