判斷虛擬機器運行在哪一套虛擬化平台上

  • 3875
  • 0
  • 2012-11-05

判斷虛擬機器運行在哪一套虛擬化平台上

 

最近看到有人發了一篇文章,想說分享一下自己的經驗,目前常見的虛擬化平台有

1. 微軟 Hyper-V

2. 微軟 VirtualPC

3. Oracle VirtualBox

4. VMWare

 

通常我是用 systeminfo 判斷大概,不過如果想要使用 C# 或 PowerShell 或 VBScript 的話,可以參考以下的說明,了解一些基本知識:

 

透過 Win32_ComputerSystem class 中的

Model:Product name that a manufacturer gives to a computer. This property must have a value. 表示系統型號。

Manufacturer:Name of a computer manufacturer. 表示系統製造商。

 

這邊使用 PowerShell 展示一下,在 VMWare 平台下的虛擬機器執行 PowerShell

輸入 (Get-WmiObject win32_computersystem).model 按 Enter 鍵

您會得到 VMware Virtual Platform

image

 

使用 systeminfo 的話,您在系統型號可以看到相同資訊

image

 

如果是在 Hyper-V 虛擬化平台下。

image

 

這邊整理一下,使用 (Get-WmiObject win32_computersystem).model 您會取得

1. 微軟 Hyper-V:Virtual Machine

2. 微軟 VirtualPC:Virtual Machine

3. Oracle VirtualBox:VirtualBox

4. VMWare:VMware Virtual Platform

 

如果您想要進一步判斷是使用 Hyper-V 還是 VirtualPC,我們可以進一步取得 Win32_BIOS class 中的 Version:Version of the BIOS. This string is created by the BIOS manufacturer. This property is inherited from CIM_SoftwareElement.

如果是 Hyper-V 平台,則在 Version 會包含 VRTUAL 字串,後面的序號則可以判斷版本,例如 5001223 表示 Hyper-V 3.0,3000919 表示 Hyper-V 2008 R2。

image

 

這邊整理一下,使用 (Get-WmiObject win32_bios).Version 您會取得:

1. 微軟 Hyper-V:包含 VRTUAL 字串。

2. 微軟 VirtualPC:包含 A M I 字串。

如果需要進一步知道版本,則需要解讀字串後的序號。

 

相關連結

PowerShell - Detect the Virtualization Layer from a guest instance(VM) - VPC or Hyper-V in C# or Powershell

VBScript - How to Tell if you are in a VM Using Script