delphi - 如何获得笔记本电脑或台式机支持的最大内存大小?

标签 delphi winapi wmi

我正在使用 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/

相关文章:

windows - 使用powershell修改本地账户

Delphi SelectClipRGN 隐藏绘制位图

delphi - 为什么在 FireMonkey Delphi 应用程序中指定运行时颜色时得到 'Undeclared identifier'?

c++ - 关于使用 C++ 使用命令行参数调用 CreateProcessAsUser 的说明

python - 使用 win32print + cx_Freeze 时,打印指令不起作用且不会产生任何错误

windows - 内核模式下的线程本地存储?

c++ - 检索 MS Windows 平台的操作系统名称

delphi - 开放式办公自动化

delphi - 使 TImage 中的每个像素变暗

javascript 使用 Firefox/chrome 进行 WMI 查询?