From 868daf94f29ce1ffdd799a68c07bb668cd373bcd Mon Sep 17 00:00:00 2001 From: HP\李良庭 <liliangting@lanpucloud.cn:1111> Date: 星期二, 08 七月 2025 11:49:03 +0800 Subject: [PATCH] 提交分辨率自适应版本V3.1.0.1500 --- src/pub/CpuidInfo.pas | 146 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 146 insertions(+), 0 deletions(-) diff --git a/src/pub/CpuidInfo.pas b/src/pub/CpuidInfo.pas new file mode 100644 index 0000000..c765159 --- /dev/null +++ b/src/pub/CpuidInfo.pas @@ -0,0 +1,146 @@ +{------------------------------------------------------------------------------} +{项目名称:获取多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. -- Gitblit v1.9.3