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;
效果图