delphi获得笔记本cpu的信息

该代码片段展示了如何使用Delphi通过WMI(WindowsManagementInstrumentation)接口获取CPU的相关信息,包括名称、描述、核心数、线程数、主频等。函数GetWMIProperty是关键,它连接到WMI服务并查询Processor类的属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 uses

uses
ActiveX, ComObj;

函数

function GetWMIProperty(WMIType, WMIProperty: AnsiString): string;
var
  Wmi, Objs, Obj: OleVariant;
  Enum: IEnumVariant;
  C: Cardinal;
begin
  try
    Wmi := CreateOleObject(AnsiString('WbemScripting.SWbemLocator'));
    Objs := Wmi.ConnectServer(AnsiString('.'), AnsiString('root\cimv2')).ExecQuery(AnsiString('Select * from Win32_' + WMIType));

    Enum := IEnumVariant(IUnknown(Objs._NewEnum));
    Enum.Reset;
    Enum.Next(1, Obj, C);
    Obj := Obj.Properties_.Item(WMIProperty, 0).Value;
    if VarIsArray(Obj) then Result := Obj[0]
    else Result := Obj;
  except
    Result := 'Error';
  end;
end;

调用

begin
  with Memo3 do
  begin           
    Lines.Add('CPU型号:          ' + GetWMIProperty('Processor', 'name'));
    Lines.Add('CPU描述:          ' + GetWMIProperty('Processor', 'Description'));
    Lines.Add('CPU核心数:       ' + GetWMIProperty('Processor', 'NumberOfCores'));
    Lines.Add('CPU ID:            ' + GetWMIProperty('Processor', 'ProcessorId'));
    Lines.Add('CPU线程数:       ' + GetWMIProperty('Processor', 'NumberOfLogicalProcessors'));
    Lines.Add('CPU主频:          ' + GetWMIProperty('Processor', 'CurrentClockSpeed') + ' MHz');
    Lines.Add('CPU外频:          ' + GetWMIProperty('Processor', 'ExtClock') + ' MHz');
    Lines.Add('CPU物料核心数: ' + GetWMIProperty('Processor', 'NumberOfCores'));
    Lines.Add('CPU逻辑核心数: ' + GetWMIProperty('Processor', 'NumberOfLogicalProcessors'));
  end;

效果图

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值