在Inno Setup中查询可用的RAM [英] Query available RAM in Inno Setup
本文介绍了在Inno Setup中查询可用的RAM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取可用的RAM才能确定软件的某些特征.
I need to get the available RAM to determinate some characteristics to my software.
我有以下代码来显示PC的RAM:
I have this code to show my PC's 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设置-如何我在安装之前/安装过程中检查系统规格吗?
推荐答案
If you already have the code for GlobalMemoryStatusEx
from Inno Setup - How can I check system specs before/during installation?, just use the ullAvailPhys
field.
另一种可能性是使用 WMI查询:
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;
另请参见是否可以通过Inno Setup读取系统信息(其中还显示了如何检索使用WMI查询的总物理内存.)
See also Is there a way to read the system's information in Inno Setup (shows, among other, how to retrieve total physical memory using WMI query).
这篇关于在Inno Setup中查询可用的RAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文