2009-12-11 68 views
1

我想檢查我的應用程序是否在VMWare上運行。 有沒有一種可靠的方法在C++中做到這一點?以編程方式檢測VMWare

+1

你爲什麼要這麼做?我想不出很多理由,在哪裏簡單的「你在一個虛擬機下運行?」對話框是不夠的(如果真的需要) – viraptor 2009-12-11 23:24:12

+0

Duplicaet http://stackoverflow.com/questions/154163/detect-virtualized-os-from-an-application – saschabeaumont 2009-12-14 01:28:59

+0

@viraptor這不是因爲你不能想想沒有的情況。例如,我正在識別計算機上的許可證和類似的東西,而且我需要知道我是否在虛擬機中,因爲這將決定我要使用哪個硬件信息,並知道如果我在虛擬機中,我必須檢查所有可能的虛擬機,包括VM Ware。 – Virus721 2014-08-04 09:19:47

回答

1

我想this link也許能幫助你。它在組裝,而不是C++,但你總是在你的C++創建裝配塊...

//////////////////////////////////////////////////////////////////////////////// 
// 
// Simple VMware check on i386 
// 
// Note: There are plenty ways to detect VMware. This short version bases 
// on the fact that VMware intercepts IN instructions to port 0x5658 with 
// an magic value of 0x564D5868 in EAX. However, this is *NOT* officially 
// documented (used by VMware tools to communicate with the host via VM). 
// 
// Because this might change in future versions - you should look out for 
// additional checks (e.g. hardware device IDs, BIOS informations, etc.). 
// Newer VMware BIOS has valid SMBIOS informations (you might use my BIOS 
// Helper unit to dump the ROM-BIOS (http://www.bendlins.de/nico/delphi). 
// 
function IsVMwarePresent(): LongBool; stdcall; // platform; 
begin 
    Result := False; 
{$IFDEF CPU386} 
    try 
    asm 
      mov  eax, 564D5868h 
      mov  ebx, 00000000h 
      mov  ecx, 0000000Ah 
      mov  edx, 00005658h 
      in  eax, dx 
      cmp  ebx, 564D5868h 
      jne  @@exit 
      mov  Result, True 
    @@exit: 
    end; 
    except 
    Result := False; 
    end; 
{$ENDIF} 
end; 

與從互聯網上的任何代碼,請注意,只複製&粘貼它,期待它完美地工作。

+0

這似乎會導致Win2k8服務器崩潰,並可能導致Windows 7 32bit操作系統不幸 – 2009-12-11 23:37:57

+1

您可能需要將其包裝在Win32「結構化」異常處理程序中。如果您獲得了無效的指令異常或類似情況,那麼您不在VMware中。 http://msdn.microsoft.com/en-us/library/s58ftw19%28VS.80%29.aspx – 2009-12-12 00:21:51

相關問題