{------------------------------------------------------------------------------} {ÏîÄ¿Ãû³Æ£º»ñÈ¡¶àCPUIDÐÅÏ¢ } {µ¥ÔªÃû³Æ£ºCpuidInfo.pas } {°æ±¾°æ´Î£º1.0 } {Ä£¿éÃû³Æ£ºÈ«¾Ö¹«¹²º¯Êý¿â } {¹¦ÄÜÃèÊö£º»ñÈ¡¶àCPUIDÏ¢(Ö§³Ö¶àºË) } {½¨Á¢ÈÕÆÚ£º2023-09-19 } {°æÈ¨ËùÓУºÀîÁ¼Í¥ } {------------------------------------------------------------------------------} unit CpuidInfo; interface uses Windows, SysUtils, StrUtils, Classes; function GetCPUID(): string; function GetCnCPUID(): string; procedure SetCPU(h: THandle;CpuNo: Integer); function CmdGetCPUID(): string; function CmdGetHDDID(): string; implementation //·½·¨Ò»£º»ñÈ¡CPUID function GetCPUID(): string; const CPUINFO = 'CPUÖÆÔìÉÌ: %SÐòÁкÅ: %X'; var s: array[0.. 19] of Char; MyCpuID: Integer; begin FillChar(s, 20, 0); asm push ebx push ecx push edx mov eax, 0 cpuid mov dword ptr s[0],ebx mov dword ptr s[4],edx mov dword ptr s[8],ecx mov eax, 1 cpuid mov MyCpuID, edx pop edx pop ecx pop ebx end; Result := Format(CPUINFO, [s, MyCpuID]); end; //·½·¨¶þ£º»ñÈ¡cpuµÄÐòÁкŠfunction GetCnCPUID(): string; const //CPUINFO= '%.8x-%.8x-%.8x-%.8x'; CPUINFO= '%.8x%.8x'; var iEax: Integer; iEbx: Integer; iEcx: Integer; iEdx: Integer; begin asm push ebx push ecx push edx mov eax, 1 DW $A20F //cpuid mov iEax, eax mov iEbx, ebx mov iEcx, ecx mov iEdx, edx pop edx pop ecx pop ebx end; //Result := Format(CPUINFO, [iEax, iEbx, iEcx, iEdx]); Result := Format(CPUINFO, [iEdx,iEax]); end; //¸ù¾ÝWindows¿ÉÒÔÉèÖýø³ÌºÍÏ̵߳ÄÇ×ÔµÐÔµÄÌØµã£¬ //ʹÓÃSetProcessAffinityMaskº¯ÊýÀ´¿ØÖÆÄĸöcpu //ÔËÐлñÈ¡ÐòÁкŵĽø³ÌÒò´ËÒ²¾Í»ñÈ¡ÁËÖ¸¶¨µÄcpu //µÄÐòÁкš£ //ΪÁ˺͵¥cpu¼æÈÝ,½¨Òé×ÜÊÇ»ñÈ¡µÚ-¸öcpuµÄÐòÀýºÅ¡£ procedure SetCPU(h: THandle; CpuNo: Integer); //CpuNo:¾ö¶¨ÁË»ñµÃµÚ¼¸¸öcpuÄں˵ĵڼ¸¸öÐòÁкŠvar ProcessAffinity: Cardinal; _SystemAffinity: Cardinal; begin GetProcessAffinityMask(h, ProcessAffinity, _SystemAffinity) ; ProcessAffinity := CpuNo; //this sets the process to only run on CPU 0 //for CPU1 only use 2 and for CPUs1&2use3 SetProcessAffinityMask(h, ProcessAffinity); end; //CMDÃüÁî»ñÈ¡CPUIDµÄ·½·¨ //wmic cpu get processorid function CmdGetCPUID(): string; var files : TStringList; begin //CMDÃüÁî»ñÈ¡macÐÅÏ¢ winexec('cmd /c wmic cpu get processorid >d:\cpuid.txt', SW_HIDE); files:= TStringList.Create; sleep(500); try try files.LoadFromFile('d:\cpuid.txt'); Result := files.Strings[1]; except Result := '0000000000000000'; end; finally FreeAndNil(files); winexec('cmd /c del d:\cpuid.txt', SW_HIDE); end; end; //CMDÃüÁî»ñÈ¡HDDIDµÄ·½·¨ //wmic diskdrive get serialnumber function CmdGetHDDID(): string; var sl : TStringList; begin //CMDÃüÁî»ñÈ¡macÐÅÏ¢ winexec('cmd /c wmic diskdrive get serialnumber >d:\a.txt', SW_HIDE); sl:= TStringList.Create; sleep(500); try try sl.LoadFromFile('d:\a.txt'); Result := sl.Strings[0]; except Result := '0000000000000000'; end; finally FreeAndNil(sl); winexec('cmd /c del d:\a.txt', SW_HIDE); end; end; end.