HP\李良庭
2025-07-08 868daf94f29ce1ffdd799a68c07bb668cd373bcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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.