4

我想在虚拟机上运行我的应用程序,但我想了解底层虚拟化层 Hyper-V、VPC(Windows/Microsoft Virtual PC) 或 VMware。如果是 VPC,我不想运行我的应用程序。我试着环顾四周但在 WIn32_BIOS/MotherBoard 上使用 WMI 提出的解决方案没有区分 Hyper-V 和 VPC。我也尝试查看代码项目中提到的指令集方法。有没有办法在两者之间进行识别(Hyper-V/VPC)?我没有要测试的 Hyper-V 设置,但我有 Virtual PC 2007。

4

1 回答 1

2

这是我开发的用于检测此功能的脚本

 Function Get-VMVirtualizationLayer{

    $Manufacturer = (Get-WmiObject win32_computersystem).manufacturer
    $model= (Get-WmiObject win32_computersystem).model
    $biosversion = (Get-WmiObject win32_bios).version

    if ($model -match "Virtual Machine")

    {

    Write-Output " Virtual Machine Running on Microsoft Virtualization Platform"


            if ($biosversion -match "VRTUAL")

            {

            Write-Output " Virtual Machine Running on Hyper-V "

            }


            elseif ($biosversion -match "A M I")

            {

            Write-Output "Virtual Machine Running on Windows Virtual PC"

            }

    }


    elseif ($model -match "VMware Virtual Platform")

    {

    Write-Output "Virtual Machine is Running on VMware Virtual Platform"

    }

    elseif ($model -match "VirtualBox")

    {

    Write-Output "Virtual Machine is Running on VirtualBox"

    }

    }


    Get-VMVirtualizationLayer

将整个代码粘贴到虚拟机上的 powershell 提示符中,它会让你知道虚拟化平台

或者您可以将整个代码复制粘贴到记事本中并将其另存为 Get-VMVirtualizationLayer.ps1

运行脚本后,您将获得所需的输出,这是我在 Hyper-V 中托管的虚拟机上运行脚本时的输出:)

PS C:\INSTALL> .\Get-VMVirtualizationLayer.ps1
 Virtual Machine Running on Microsoft Virtualization Platform
 Virtual Machine Running on Hyper-V
PS C:\INSTALL>
于 2012-10-31T14:08:14.140 回答