delphi读cpu序列号问题
下面代码大家帮测试下。是不是都能获得值。有错误弹出没??
function GetCpuInfo(): string;var R: array[0..19] of Char; CID: Integer;begin FillChar(R, 20, 0); asm push ebx push ecx push edx mov eax, 0 cpuid mov dword ptr R[0], ebx mov dword ptr R[4], edx mov dword ptr R[8], ecx mov eax, 1 cpuid mov CID, edx pop edx pop ecx pop ebx end; Result := R + inttostr(CID);end;
implementation uses ActiveX, ComObj;{$R *.dfm}function GetWMIProperty(WMIType, WMIProperty:String):String;var Wmi, Objs, Obj:OleVariant; Enum:IEnumVariant; C:Cardinal;begin try Wmi:= CreateOleObject('WbemScripting.SWbemLocator'); Objs := Wmi.ConnectServer('.','root\cimv2').ExecQuery('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;
[解决办法]
没有报错,厂商是对的,不过ID不知道对不对。
[解决办法]
delphi7 + win2003
GetCpuInfo没有出错误,不知道结果对不对
出错误
ShowMessage(GetWMIProperty('DiskDrive','SerialNumber')); //获得第一块硬盘的设备标示