读取CPU型号。 function TViewSystemInfoFrm.GetCPUname: string; var Reg: TRegistry; begin Result := ''; Reg := TRegistry.Create; try Reg.RootKey := HKEY_LOCAL_MACHINE; if Reg.OpenKey('\Hardware\Description\System\CentralProcessor\0', False) then Result := Reg.ReadString('ProcessorNameString'); finally Reg.Free; end; end;//只能读取到线程数,核心数求教中。CPUCount 是system 下面的可以直接用。 Memo1.Lines.Add(Format('1、 系统中共有 核心数/%d 线程数',[CPUCount]));
貌似读取回来的信息不对啊。我是I5的cpu读取回来的怎么是奔腾的呢。也没有读取内存型号的代码。
可以读取到cpu 的型号了。cpu核心数和内存型号帮帮忙补充一下好不。。
请查阅WMI, 在Delphi里需要先导入 Microsoft WMIScripting V1.x Library, Component->Import Component->Import type library->"先中类库"->Add unit to project
http://xeonfeng.bokee.com/4938068.html
function TViewSystemInfoFrm.GetCPUname: string;
var
Reg: TRegistry;
begin
Result := '';
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\Hardware\Description\System\CentralProcessor\0', False) then
Result := Reg.ReadString('ProcessorNameString');
finally
Reg.Free;
end;
end;//只能读取到线程数,核心数求教中。CPUCount 是system 下面的可以直接用。
Memo1.Lines.Add(Format('1、 系统中共有 核心数/%d 线程数',[CPUCount]));
在Delphi里需要先导入 Microsoft WMIScripting V1.x Library, Component->Import Component->Import type library->"先中类库"->Add unit to project
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;procedure TForm1.Button1Click(Sender: TObject);
begin
// ShowMessage(GetWMIProperty('BIOS','BIOSVersion')); //获得BIOS版本
ShowMessage(GetWMIProperty('DiskDrive','SerialNumber')); //获得第一块硬盘的设备标示
// ShowMessage(GetWMIProperty('Processor','ProcessorId')); //获得CPUID。
end;
用api
要获取各种硬件的详细信息,还是得需要在Ring0下面弄