如何在delphi中获取CPU的序列号?(100分)

  • 主题发起人 主题发起人 macwolf
  • 开始时间 开始时间
M

macwolf

Unregistered / Unconfirmed
GUEST, unregistred user!
程序中需要使用来判断是否是合法的用户,主板或者CPU序列号都可以!<br>使用在windows2000系统中!<br>谢谢!
 
用CPUID指令,首先你可以确定你用的CPU是Intel的。<br>然后执行:<br>&nbsp; &nbsp; MOV EAX,01H<br>&nbsp; &nbsp; CPUID<br>如果返回的EDX中,低18位为1,那么这个CPU就是支持序列号的。<br>此时EAX就是序列号的高32位。这32位对同一型号的CPU是一样的。<br>再执行:<br>&nbsp; &nbsp; MOV EAX,03H<br>&nbsp; &nbsp; CPUID<br>此时的EDX:ECX就是序列号的第64位。
 
获得Intel CPU的信息<br>下面这个函数会返回一个字符串列表及特性集合,这个函数只对Intel 486及以上的CPU有效。其他CPU将返回[cpuNonIntel] 或 [cpuNoCPUID].<br><br>用法:<br><br>GetCpuFeatures(memo1.Lines);<br><br>支持的特性<br>---------------------------------------<br>CPU Family 6<br>CPU Model 7<br>CPU Stepping 3<br>On-Chip FPU<br>VirtualMode Extensions<br>Debugging Extensions<br>Page Size Extensions<br>Time Stamp Counter<br>Model Specific Registers<br>Physical Address Extensions<br>Machine Check Extensions<br>CMPXCHG8B Instruction<br>Fast System Call<br>Memory Type Range Registers<br>Page Global Enable<br>Machine Check Architecture<br>Conditional Move Instruction<br>Page Attribute Table<br>32 Bit Page Size Extension<br>Intel MMX Technology<br>Fast Floating Point Save and Restore<br>Streaming SIMD Extensions<br><br>unit Unit2;<br>interface<br>uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms;<br><br>type<br>&nbsp; TForm2 = class(TForm)<br>&nbsp; private<br>&nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; { Public declarations } &nbsp; end;<br><br>&nbsp; TCpuFeature = (cpuNoCPUID,cpuNonIntel,cpuOnChipFPU,<br>&nbsp; cpuVirtualModeExtensions,cpuDebuggingExtensions,<br>&nbsp; cpuPageSizeExtensions,cpuTimeStampCounter,<br>&nbsp; cpuModelSpecificRegisters,cpuPhysicalAddressExtensions,<br>&nbsp; cpuMachineCheckExtensions,cpuCMPXCHG8B,cpuOnChipAPIC,<br>&nbsp; cpuFastSystemCall,cpuMemoryRangeRegisters,cpuPageGlobalEnable,<br>&nbsp; cpuMachineCheckArchitecture,cpuConditionalMoveInstruction,<br>&nbsp; cpuPageAttributeTable,cpu32bitPageSzExtension,<br>&nbsp; cpuProcessorSerialNum,cpuMMXTechnology,cpuFastFloatingPoint,<br>&nbsp; cpuSIMDExtensions);<br><br>&nbsp; TCpuFeatures = set of TCpuFeature;<br><br>&nbsp; function GetCpuFeatures(FeatureList : TStrings = nil) : TCpuFeatures;<br><br>var Form2: TForm2;<br>implementation<br>{$R *.DFM}<br><br>function GetCpuFeatures(FeatureList : TStrings = nil) : TCpuFeatures;<br>const<br>&nbsp; FPU_FLAG = $0001;<br>&nbsp; VME_FLAG = $0002;<br>&nbsp; DE_FLAG = $0004;<br>&nbsp; PSE_FLAG = $0008;<br>&nbsp; TSC_FLAG = $0010;<br>&nbsp; MSR_FLAG = $0020;<br>&nbsp; PAE_FLAG = $0040;<br>&nbsp; MCE_FLAG = $0080;<br>&nbsp; CX8_FLAG = $0100;<br>&nbsp; APIC_FLAG = $0200;<br>&nbsp; SEP_FLAG = $0800;<br>&nbsp; MTRR_FLAG = $1000;<br>&nbsp; PGE_FLAG = $2000;<br>&nbsp; MCA_FLAG = $4000;<br>&nbsp; CMOV_FLAG = $8000;<br>&nbsp; PAT_FLAG = $10000;<br>&nbsp; PSE36_FLAG = $20000;<br>&nbsp; PSNUM_FLAG = $40000;<br>&nbsp; MMX_FLAG = $800000;<br>&nbsp; FXSR_FLAG = $1000000;<br>&nbsp; SIMD_FLAG = $2000000;<br><br>var IsIntel : boolean;<br>&nbsp; VendorID : array [0..12] of char;<br>&nbsp; IntelID : array [0..12] of char;<br>&nbsp; FeaturesFlag,CpuSignature : DWord;<br>&nbsp; Temp : DWord;<br>&nbsp; RetVar : TCpuFeatures;<br>&nbsp; CpuType : byte;<br><br>&nbsp; procedure CheckFeature(FeatureFlag : DWord;<br>&nbsp; const Item : string;<br>&nbsp; cpuFeatureType : TCpuFeature);<br>&nbsp; begin<br>&nbsp; if FeaturesFlag and FeatureFlag = FeatureFlag then begin<br>&nbsp; if FeatureList &lt;&gt; nil then FeatureList.Add(Item);<br>&nbsp; include(RetVar,cpuFeatureType);<br>&nbsp; end;<br>&nbsp; end;<br><br>begin<br>&nbsp; RetVar := [];<br>&nbsp; if FeatureList &lt;&gt; nil then FeatureList.Clear;<br>&nbsp; IsIntel := false;<br>&nbsp; IntelId := 'GenuineIntel'#0;<br>&nbsp; VendorID := '------------'#0;<br><br>&nbsp; try<br>&nbsp; asm<br><br>&nbsp; //确认是否支持Intel CPUID调用<br>&nbsp; push ebx<br>&nbsp; push esi<br>&nbsp; push edi<br>&nbsp; mov eax,0 // Set up for CPUID instruction<br>&nbsp; db 00fh // CPUID - Get Vendor and check INTEL<br>&nbsp; db 0a2h<br>&nbsp; mov dword ptr VendorId,ebx<br>&nbsp; mov dword ptr VendorId[+4],edx<br>&nbsp; mov dword ptr VendorId[+8],ecx<br>&nbsp; cmp dword ptr IntelId,ebx //检查是否是Intel CPU<br>&nbsp; jne @@EndCPUID<br>&nbsp; cmp dword ptr IntelId[+4],edx<br>&nbsp; jne @@EndCPUID<br>&nbsp; cmp dword ptr IntelId[+8],ecx<br>&nbsp; jne @@EndCPUID // 非Intel CPU<br><br>&nbsp; mov byte ptr IsIntel,1 // Set IsIntel to true<br>&nbsp; cmp eax,1 // Ensure 1 is valid input for CPUID<br>&nbsp; jl @@EndCPUID // Else jump to end<br><br>&nbsp; mov eax,1<br>&nbsp; db 00fh // CPUID - Get features,family etc.<br>&nbsp; db 0a2h<br>&nbsp; mov CpuSignature,eax<br>&nbsp; mov FeaturesFlag,edx<br>&nbsp; shr eax,8 // Isolate family<br>&nbsp; and eax,0fh<br>&nbsp; mov byte ptr CpuType,al // Set cputype with family<br><br>&nbsp; @@EndCPUID :<br><br>&nbsp; pop edi // 恢复寄存器<br>&nbsp; pop esi<br>&nbsp; pop ebx<br>&nbsp; end;<br><br>&nbsp; // 检查特性掩码<br>&nbsp; if IsIntel then begin<br>&nbsp; if FeatureList &lt;&gt; nil then begin<br>&nbsp; FeatureList.Add('CPU Family ' + IntToStr(CpuType));<br>&nbsp; Temp := (CpuSignature shr 4) and $0f;<br>&nbsp; FeatureList.Add('CPU Model ' + IntToStr(Temp));<br>&nbsp; Temp := CpuSignature and $0f;<br>&nbsp; FeatureList.Add('CPU Stepping ' + IntToStr(Temp));<br>&nbsp; end;<br><br>&nbsp; CheckFeature(FPU_FLAG,'On-Chip FPU',cpuOnChipFPU);<br>&nbsp; CheckFeature(VME_FLAG,<br>&nbsp; 'VirtualMode Extensions',cpuVirtualModeExtensions);<br>&nbsp; CheckFeature(DE_FLAG,'Debugging Extensions',cpuDebuggingExtensions);<br>&nbsp; CheckFeature(PSE_FLAG,'Page Size Extensions',cpuPageSizeExtensions);<br>&nbsp; CheckFeature(TSC_FLAG,'Time Stamp Counter',cpuTimeStampCounter);<br>&nbsp; CheckFeature(MSR_FLAG,<br>&nbsp; 'Model Specific Registers',cpuModelSpecificRegisters);<br>&nbsp; CheckFeature(PAE_FLAG,<br>&nbsp; 'Physical Address Extensions',<br>&nbsp; cpuPhysicalAddressExtensions);<br>&nbsp; CheckFeature(MCE_FLAG,<br>&nbsp; 'Machine Check Extensions',cpuMachineCheckExtensions);<br>&nbsp; CheckFeature(CX8_FLAG,'CMPXCHG8B Instruction',cpuCMPXCHG8B);<br>&nbsp; CheckFeature(APIC_FLAG,'On Chip APIC',cpuOnChipAPIC);<br>&nbsp; CheckFeature(SEP_FLAG,'Fast System Call',cpuFastSystemCall);<br>&nbsp; CheckFeature(MTRR_FLAG,<br>&nbsp; 'Memory Type Range Registers',cpuMemoryRangeRegisters);<br>&nbsp; CheckFeature(PGE_FLAG,'Page Global Enable',cpuPageGlobalEnable);<br>&nbsp; CheckFeature(MCA_FLAG,<br>&nbsp; 'Machine Check Architecture',cpuMachineCheckArchitecture);<br>&nbsp; CheckFeature(CMOV_FLAG,<br>&nbsp; 'Conditional Move Instruction',<br>&nbsp; cpuConditionalMoveInstruction);<br>&nbsp; CheckFeature(PAT_FLAG,'Page Attribute Table',cpuPageAttributeTable);<br>&nbsp; CheckFeature(PSE36_FLAG,<br>&nbsp; '32 Bit Page Size Extension',cpu32BitPageSzExtension);<br>&nbsp; CheckFeature(PSNUM_FLAG,<br>&nbsp; 'Processor Serial Number',cpuProcessorSerialNum);<br>&nbsp; CheckFeature(MMX_FLAG,'Intel MMX Technology',cpuMMXTechnology);<br>&nbsp; CheckFeature(FXSR_FLAG,<br>&nbsp; 'Fast Floating Point Save and Restore',<br>&nbsp; cpuFastFloatingPoint);<br>&nbsp; CheckFeature(SIMD_FLAG,'Streaming SIMD Extensions',cpuSIMDExtensions);<br>&nbsp; end<br>&nbsp; else begin<br>&nbsp; if FeatureList &lt;&gt; nil then<br>&nbsp; FeatureList.Add('Non-Intel or &gt;486 Chip - Features Unknown');<br>&nbsp; include(RetVar,cpuNonIntel);<br>&nbsp; end;<br>&nbsp; except<br>&nbsp; if FeatureList &lt;&gt; nil then FeatureList.Add('No CPUID Support');<br>&nbsp; include(RetVar,cpuNoCPUID);<br>&nbsp; end;<br><br>&nbsp; Result := RetVar;<br>end;<br><br>end.<br><br>
 
后退
顶部