是否有可能使用C#来检查是否启用硬件虚拟化? [英] Is it possible using C# to check if hardware virtualization enabled?

查看:515
本文介绍了是否有可能使用C#来检查是否启用硬件虚拟化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找不到答案,所以我想我要求自己。



使用C#,我怎么能检测CPU是否启用了硬件虚拟化?的Hyper-V,例如。这不是在 Win32_Processor 类,我尝试连接到 MSVM_ComputerSystem 与彻底的失败满足。不断告诉我有一个无效的命名空间。



代码的下方。

  ManagementObjectSearcher VM =新ManagementObjectSearcher(@\\.\root\virtualization,SELECT * FROM MSVM_Computersystem); 
ManagementObjectCollection vmCollection = vm.Get();
的foreach(在vmCollection的ManagementObject MO)
{
cpuVirtual = MO [EnabledState]的ToString()。
}


解决方案

如果您枚举所有属性Win32_Processor类,你会看到一个名为财产 VirtualizationFirmwareEnabled ,我认为你是在谈论这个属性。



正如你可以看到的此链接,检查是否一些机处理器能够在Hyper-V上运行,它们使用 VirtualizationFirmwareEnabled 结合其他性能:



我写了这个简单的文档片断遍历所有win32_processor类值:

  ManagementClass managClass =新ManagementClass(win32_processor); 
ManagementObjectCollection managCollec = managClass.GetInstances();

的foreach(的ManagementObject managObj在managCollec)
{
的foreach(在managObj.Properties VAR道具)
{
Console.WriteLine(物业名称:{0}值:{1},prop.Name,道具.value的);
}
}

Console.ReadKey();


Couldn't find an answer, so I thought I ask for myself.

Using C#, how can I check if the CPU has hardware virtualization enabled? Hyper-V, for example. It's not in the Win32_Processor class, and my attempt to connect to the MSVM_ComputerSystem was met with utter failure. Keeps telling me there's an invalid namespace.

Code below.

ManagementObjectSearcher vm = new ManagementObjectSearcher(@"\\.\root\virtualization", "select * from MSVM_Computersystem");
ManagementObjectCollection vmCollection = vm.Get();
foreach (ManagementObject mo in vmCollection)
{
     cpuVirtual = mo["EnabledState"].ToString();
}

解决方案

if you enumerate all properties in Win32_Processor class, you see a property named "VirtualizationFirmwareEnabled", I think you are talking about this property.

As you can see in this link, to check if some machine processor can run on Hyper-V, they use VirtualizationFirmwareEnabled" in conjunction to other properties:

I wrote this simple snipped to iterate over all win32_processor class values:

ManagementClass managClass = new ManagementClass("win32_processor");
ManagementObjectCollection managCollec = managClass.GetInstances();

foreach (ManagementObject managObj in managCollec)
{
   foreach (var prop in managObj.Properties)
   {
       Console.WriteLine("Property Name: {0} Value: {1}",prop.Name,prop.Value);
   }               
}

Console.ReadKey();

这篇关于是否有可能使用C#来检查是否启用硬件虚拟化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆