| 发表于:2007-03-02 10:03:263楼 得分:3 |
* 这个模块是用来获取cpu、硬盘序列号,cpu的* * * * 速率、显示器的刷新率网卡的mac地址等信息 * unit hardinfo; interface uses windows,sysutils,nb30; const id_bit = $200000; // eflags id bit type tcpuid = array[1..4] of longint; tvendor = array [0..11] of char; function iscpuid_available : boolean; register; //判断cpu序列号是否可用函数 function getcpuid: tcpuid; assembler; register; //获取cpu序列号函数 function getcpuvendor: tvendor; assembler; register; //获取cpu生产厂家函数 function getcpuinfo: string; //cpu序列号(格式化成字符串) function getcpuspeed: double; //获取cpu速度函数 function getdisplayfrequency: integer; //获取显示器刷新率 function getideserialnumber: pchar; //获取ide硬盘序列号函数 function monthmaxday(year,month:integer):integer; //获取某年某月的最大天数 function getadaptermac(ano:integer):string; implementation function iscpuid_available : boolean; register; asm pushfd {direct access to flags no possible, only via stack} pop eax {flags to eax} mov edx,eax {save current flags} xor eax,id_bit {not id bit} push eax {onto stack} popfd {from stack to flags, with not id bit} pushfd {back to stack} pop eax {get back to eax} xor eax,edx {check if id bit affected} jz @exit {no, cpuid not availavle} mov al,true {result=true} @exit: end; function getcpuid: tcpuid; assembler; register; asm push ebx {save affected register} push edi mov edi,eax {@resukt} mov eax,1 dw $a20f {cpuid command} stosd {cpuid[1]} mov eax,ebx stosd {cpuid[2]} mov eax,ecx stosd {cpuid[3]} mov eax,edx stosd {cpuid[4]} pop edi {restore registers} pop ebx end; function getcpuvendor : tvendor; assembler; register; //获取cpu生产厂家函数 //调用方法:edit.text:= 'current cpu vendor: '+getcpuvendor; asm push ebx {save affected register} push edi mov edi,eax {@result (tvendor)} mov eax,0 dw $a20f {cpuid command} mov eax,ebx xchg ebx,ecx {save ecx result} mov ecx,4 @1: stosb shr eax,8 loop @1 mov eax,edx mov ecx,4 @2: stosb shr eax,8 loop @2 mov eax,ebx mov ecx,4 @3: stosb shr eax,8 loop @3 pop edi {restore registers} pop ebx end; function getcpuinfo: string; var cpuid: tcpuid; i: integer; s: tvendor; begin for i:=low(cpuid) to high(cpuid) do cpuid[i]:=-1; if iscpuid_available then begin cpuid:= getcpuid; s:=getcpuvendor; result:= inttohex(cpuid[1], 8) + '- '+ inttohex(cpuid[2], 8) + '- '+ inttohex(cpuid[3], 8) + '- '+ inttohex(cpuid[4], 8); end else result:= 'cpuid not available '; end; function getcpuspeed: double; //获取cpu速率函数 //调用方法:edit.text:= 'current cpu speed: '+floattostr(getcpuspeed)+ 'mhz '; const delaytime = 500; // 时间单位是毫秒 var timerhi, timerlo: dword; priorityclass, priority: integer; begin priorityclass := getpriorityclass(getcurrentprocess); priority := getthreadpriority(getcurrentthread); setpriorityclass(getcurrentprocess, realtime_priority_class); setthreadpriority(getcurrentthread, thread_priority_time_critical); sleep(10); asm dw 310fh // rdtsc mov timerlo, eax mov timerhi, edx end; sleep(delaytime); asm dw 310fh // rdtsc sub eax, timerlo sbb edx, timerhi mov timerlo, eax mov timerhi, edx end; setthreadpriority(getcurrentthread, priority); setpriorityclass(getcurrentprocess, priorityclass); result := timerlo / (1000.0 * delaytime); end; function getdisplayfrequency: integer; // 这个函数返回的显示刷新率是以hz为单位的 //调用方法:edit.text:= 'current displayfrequency: '+inttostr(getdisplayfrequency)+ ' hz '; var devicemode: tdevicemode; begin enumdisplaysettings(nil, cardinal(-1), devicemode); result := devicemode.dmdisplayfrequency; end; | | |
|