How to determine if hardware virtualization is available via code? (C#, C++)

15,283

Solution 1

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.

Solution 2

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

Share:
15,283
Raj Rao
Author by

Raj Rao

http://blog.aggregatedIntelligence.com

Updated on June 04, 2022

Comments

  • Raj Rao
    Raj Rao about 2 years

    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?

  • Raj Rao
    Raj Rao about 15 years
    Exactly like this application - but I need to do it in code. I have searched WMI query results high and low and could not find any property that seemed to be connected to HW virtualization
  • Der_Meister
    Der_Meister about 6 years
    Both commands return False for me, but I have Hyper-V virtualization enabled.