我正在使用 Delphi 构建软件以获取一些硬件信息,我需要使用 Delphi 获取笔记本电脑或台式机支持的最大内存 (RAM) 大小,到目前为止,我一直在寻找 WinApi 或 WMI 函数来获取该信息,但我没有找到与此相关的任何信息。如何获得笔记本电脑或台式机支持的最大内存大小?
最佳答案
您可以使用 SMBIOS要获取该信息,请尝试阅读有关 Physical Memory Array (Type 16)
的文档 table 。你可以parse and extract the SMBIOS tables manually或使用类似 TSMBIOS 的库.
试试这个使用 TSMBIOS 库的示例。
{$APPTYPE CONSOLE}
uses
Classes,
SysUtils,
uSMBIOS in '..\..\Common\uSMBIOS.pas';
function GetMaxMemoryCapacity : UInt32;
Var
SMBios : TSMBios;
LPhysicalMemArr : TPhysicalMemoryArrayInformation;
begin
result:=0;
SMBios:=TSMBios.Create;
try
if SMBios.HasPhysicalMemoryArrayInfo then
for LPhysicalMemArr in SMBios.PhysicalMemoryArrayInfo do
begin
if LPhysicalMemArr.RAWPhysicalMemoryArrayInformation.MaximumCapacity<>$80000000 then
result:=result+(LPhysicalMemArr.RAWPhysicalMemoryArrayInformation.MaximumCapacity*LPhysicalMemArr.RAWPhysicalMemoryArrayInformation.NumberofMemoryDevices)
else
result:=result+((LPhysicalMemArr.RAWPhysicalMemoryArrayInformation.ExtendedMaximumCapacity div 1024)*LPhysicalMemArr.RAWPhysicalMemoryArrayInformation.NumberofMemoryDevices);
end
else raise Exception.Create('No Physical Memory Array Info was found');
finally
SMBios.Free;
end;
end;
begin
try
Writeln(Format('Max Memory Capacity installable %d kb',[GetMaxMemoryCapacity]));
except
on E:Exception do
Writeln(E.Classname, ':', E.Message);
end;
Writeln('Press Enter to exit');
Readln;
end.
关于delphi - 如何获得笔记本电脑或台式机支持的最大内存大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16156195/