Question

How can I detect if a system supports hardware virtualization via code? (Preferably in C# or C++).

I tried using WMI and ManagementObjectSearcher, and could not find a property that seemed to represent if virtualization support was present or not in the machine.

Bonus question: Is it possible to tell if the CPU supports HW virtualization, but disabled in BIOS?

Was it helpful?

Solution

I think the original poster is asking how to detect that the computer hardware supports virtualisation, not that it is running inside a virtual machine. See this question for a possible answer.

Also, it might be worth seeing if you can check the CPU flags, as there will either be the Intel vmx flag or the AMD svm flag if the processor supports virtualisation extensions. I can't say I know how this should be done under Windows, but the information is available in /proc/cpuinfo on Linux.

OTHER TIPS

I do not have a C-ish answer, but here's a PowerShell approach -- it's just a simple WMI query -- that can help.

Query Win32_Processor; there are flags "SecondLevelAddressTranslationExtensions" and "VirtualizationFirmwareEnabled." They seem to answer the questions for me.

In PoSH, it's

(GWMI Win32_Processor).VirtualizationFirmwareEnabled

and

(GWMI Win32_Processor).SecondLevelAddressTranslationExtensions

I hope this helps.

Mark Minasi

Not sure on the code, but Securable seems to be able to do this.

Check this link, as you can see there, maybe you should use WMI classes to get info. .NET framework has System.Management namespace to do that. Win32_processor class can give you all info you need about processor, because you can't access the cpu flags directly using win32_processor class, maybe you need to check the value of VirtualizationFirmwareEnabled

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