我已经尝试过这个单元来检测我的应用程序是否在 Oracle VirtualBox 中运行,但它没有检测到 VirtualBox。
我已经在 VirtualBox 中安装了 Windows 7 对其进行了测试。
有什么有效的方法可以防止我的 VCL 应用程序在 VirtualBox 中运行?
我已经尝试过这个单元来检测我的应用程序是否在 Oracle VirtualBox 中运行,但它没有检测到 VirtualBox。
我已经在 VirtualBox 中安装了 Windows 7 对其进行了测试。
有什么有效的方法可以防止我的 VCL 应用程序在 VirtualBox 中运行?
您可以使用Win32_BaseBoard WMI 类并检查产品字符串是否包含单词“ Virtual
”
例如 :
function _IsOSVirtual(): Boolean;
const
v = 'virtual';
Begin
Result := False;
CoInitialize(nil);
try
if Pos(v, LowerCase(GetWin32_BaseBoard('Product'))) > 0 then
Result := True;
finally
CoUninitialize;
end;
end;
如果您可以获取 Bios 信息(使用 WMI 或其他方法),您可以找到 VirtualBox 的痕迹。
instance of Win32_BIOS
{
...
BIOSVersion = {"VBOX - 1"};
Caption = "Default System BIOS";
Description = "Default System BIOS";
Manufacturer = "innotek GmbH";
Name = "Default System BIOS";
SerialNumber = "0";
SMBIOSBIOSVersion = "VirtualBox";
SMBIOSPresent = TRUE;
SoftwareElementID = "Default System BIOS";
SoftwareElementState = 3;
Status = "OK";
Version = "VBOX - 1";
};
继续使用 WMI 其他类可以帮助您识别 VirtualBox 安装。例如这个查询:
Select Manufacturer, Model, OEMStringArray from Win32_ComputerSystem
返回此值:
instance of Win32_ComputerSystem
{
Manufacturer = "innotek GmbH";
Model = "VirtualBox";
OEMStringArray = {"vboxVer_5.1.22", "vboxRev_115126"};
};
function IsRunningVirtualBox : Boolean;
var
vHandle : THandle;
begin
Result := false;
vHandle := LoadLibrary('VBoxHook.dll');
if vHandle <> 0 then begin
Result := true;
FreeLibrary(vHandle);
end;
end;