我需要获取可用的RAM来确定我的软件的某些特性。
我有这个代码来显示我的PC的RAM:
type
DWORDLONG = Int64;
TMemoryStatusEx = record
dwLength: DWORD;
dwMemoryLoad: DWORD;
ullTotalPhys: DWORDLONG;
ullAvailPhys: DWORDLONG;
ullTotalPageFile: DWORDLONG;
ullAvailPageFile: DWORDLONG;
ullTotalVirtual: DWORDLONG;
ullAvailVirtual: DWORDLONG;
ullAvailExtendedVirtual: DWORDLONG;
end;
function GlobalMemoryStatusEx(var lpBuffer: TMemoryStatusEx): BOOL;
external 'GlobalMemoryStatusEx@kernel32.dll stdcall';
function InitializeSetup: Boolean;
var
MemoryStatus: TMemoryStatusEx;
RAM: String;
begin
Result := True;
MemoryStatus.dwLength := SizeOf(MemoryStatus);
if GlobalMemoryStatusEx(MemoryStatus) then
begin
RAM := Int64ToStr(MemoryStatus.ullTotalPhys/1000000000);
MsgBox('This PC has '+RAM+' GB of RAM', mbInformation, MB_OK);
end;
end;
基于Inno Setup - How can I check system specs before/during installation?
答案 0 :(得分:3)
如果您已经拥有Inno Setup - How can I check system specs before/during installation? GlobalMemoryStatusEx
的代码,请使用ullAvailPhys
字段。
另一种可能性是使用WMI query:
var
Query: string;
WbemLocator, WbemServices, WbemObjectSet: Variant;
OperatingSystem: Variant;
begin
WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
WbemServices := WbemLocator.ConnectServer('.', 'root\CIMV2');
Query := 'SELECT FreePhysicalMemory FROM Win32_OperatingSystem';
WbemObjectSet := WbemServices.ExecQuery(Query);
if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then
begin
OperatingSystem := WbemObjectSet.ItemIndex(0);
Log(Format('Free physical memory = %d GB', [
Integer(OperatingSystem.FreePhysicalMemory div (1024*1024))]));
end;
end;
另请参阅Is there a way to read the system's information in Inno Setup(其中包括如何使用WMI查询检索总物理内存)。
答案 1 :(得分:1)
阅读ullAvailPhys
字段:
type
DWORDLONG = Int64;
TMemoryStatusEx = record
dwLength: DWORD;
dwMemoryLoad: DWORD;
ullTotalPhys: DWORDLONG;
ullAvailPhys: DWORDLONG;
ullTotalPageFile: DWORDLONG;
ullAvailPageFile: DWORDLONG;
ullTotalVirtual: DWORDLONG;
ullAvailVirtual: DWORDLONG;
ullAvailExtendedVirtual: DWORDLONG;
end;
function GlobalMemoryStatusEx(var lpBuffer: TMemoryStatusEx): BOOL;
external 'GlobalMemoryStatusEx@kernel32.dll stdcall';
function InitializeSetup: Boolean;
var
MemoryStatus: TMemoryStatusEx;
RAM, Available: String;
begin
Result := True;
MemoryStatus.dwLength := SizeOf(MemoryStatus);
{ if the GlobalMemoryStatusEx function call succeed, then... }
if GlobalMemoryStatusEx(MemoryStatus) then
begin
RAM := Int64ToStr(MemoryStatus.ullTotalPhys/1000000000);
Available := Int64ToStr(MemoryStatus.ullAvailPhys/1000000000)
MsgBox('This PC has '+RAM+' GB of RAM, Available ' + Available, mbInformation, MB_OK);
end;
end;