unit Secrity;  

interface  

uses  

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  

Dialogs, StdCtrls,nb30;{重要引用}  

type  

PASTAT = ^TASTAT;  

TASTAT = record  

    adapter : TAdapterStatus;  

    name_buf : TNameBuffer;  

end;  

TForm1 = class(TForm)  

    Button1: TButton;  

    Edit1: TEdit;  

    procedure Button1Click(Sender: TObject);  

private  

    { Private declarations }  

public  

    { Public declarations }  

end;  

var  

Form1: TForm1;  

implementation  

{$R *.dfm}  

type  

TCPUID = array[..] of Longint;  

//取硬盘系列号:  

function GetIdeSerialNumber: pchar; //获取硬盘的出厂系列号;  

const IDENTIFY_BUFFER_SIZE = ;  

type  

   TIDERegs = packed record  

     bFeaturesReg: BYTE;  

     bSectorCountReg: BYTE;  

     bSectorNumberReg: BYTE;  

     bCylLowReg: BYTE;  

     bCylHighReg: BYTE;  

     bDriveHeadReg: BYTE;  

     bCommandReg: BYTE;  

     bReserved: BYTE;  

end;  

TSendCmdInParams = packed record  

    cBufferSize: DWORD;  

    irDriveRegs: TIDERegs;  

    bDriveNumber: BYTE;  

    bReserved: array[..] of Byte;  

    dwReserved: array[..] of DWORD;  

    bBuffer: array[..] of Byte;  

end;  

TIdSector = packed record  

    wGenConfig: Word;  

    wNumCyls: Word;  

    wReserved: Word;  

    wNumHeads: Word;  

    wBytesPerTrack: Word;  

    wBytesPerSector: Word;  

    wSectorsPerTrack: Word;  

    wVendorUnique: array[..] of Word;  

    sSerialNumber: array[..] of CHAR;  

    wBufferType: Word;  

    wBufferSize: Word;  

    wECCSize: Word;  

    sFirmwareRev: array[..] of Char;  

    sModelNumber: array[..] of Char;  

    wMoreVendorUnique: Word;  

    wDoubleWordIO: Word;  

    wCapabilities: Word;  

    wReserved1: Word;  

    wPIOTiming: Word;  

    wDMATiming: Word;  

    wBS: Word;  

    wNumCurrentCyls: Word;  

    wNumCurrentHeads: Word;  

    wNumCurrentSectorsPerTrack: Word;  

    ulCurrentSectorCapacity: DWORD;  

    wMultSectorStuff: Word;  

    ulTotalAddressableSectors: DWORD;  

    wSingleWordDMA: Word;  

    wMultiWordDMA: Word;  

    bReserved: array[..] of BYTE;  

end;  

PIdSector = ^TIdSector;  

TDriverStatus = packed record  

    bDriverError: Byte;  

    bIDEStatus: Byte;  

    bReserved: array[..] of Byte;  

    dwReserved: array[..] of DWORD;  

end;  

TSendCmdOutParams = packed record  

    cBufferSize: DWORD;  

    DriverStatus: TDriverStatus;  

    bBuffer: array[..] of BYTE;  

end;  

var  

hDevice: Thandle;  

cbBytesReturned: DWORD;  

SCIP: TSendCmdInParams;  

aIdOutCmd: array[..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE-)-] of Byte;  

IdOutCmd: TSendCmdOutParams absolute aIdOutCmd;  

procedure ChangeByteOrder(var Data; Size: Integer);  

var  

ptr: Pchar;  

i: Integer;  

c: Char;  

begin  

ptr := @Data;  

for I :=  to (Size shr ) -  do begin  

    c := ptr^;  

    ptr^ := (ptr + )^;  

    (ptr + )^ := c;  

    Inc(ptr, );  

end;  

end;  

begin  

    Result := '';  

    if SysUtils.Win32Platform = VER_PLATFORM_WIN32_NT then  

       begin // Windows NT, Windows   

         hDevice := CreateFile('//./PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,  

         FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, , );  

       end  

    else // Version Windows  OSR2, Windows   

       hDevice := CreateFile('//./SMARTVSD', , , nil, CREATE_NEW, , );  

    if hDevice = INVALID_HANDLE_VALUE then Exit;  

    try  

      FillChar(SCIP, SizeOf(TSendCmdInParams) - , #);  

      FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #);  

      cbBytesReturned := ;  

      with SCIP do  

      begin  

        cBufferSize := IDENTIFY_BUFFER_SIZE;  

        with irDriveRegs do  

        begin  

          bSectorCountReg := ;  

          bSectorNumberReg := ;  

          bDriveHeadReg := $A0;  

          bCommandReg := $EC;  

        end;  

      end;  

      if not DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - ,@aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil) then Exit;  

    finally  

      CloseHandle(hDevice);  

    end;  

    with PIdSector(@IdOutCmd.bBuffer)^ do  

    begin  

      ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber));  

      (Pchar(@sSerialNumber) + SizeOf(sSerialNumber))^:= #;  

      Result := Pchar(@sSerialNumber);  

    end;  

end;  

//=================================================================  

//CPU系列号:  

FUNCTION GetCPUID : TCPUID; assembler; register;  

asm  

PUSH    EBX         {Save affected register}  

PUSH    EDI  

MOV     EDI,EAX     {@Resukt}  

MOV     EAX,  

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 GetCPUIDStr:String;  

var  

CPUID:TCPUID;  

begin  

CPUID:=GetCPUID;  

Result:=IntToHex(CPUID[],)+IntToHex(CPUID[],)+IntToHex(CPUID[],)+IntToHex(CPUID[],);  

end;  

///==================================================================================  

///取MAC(非集成网卡):  

function NBGetAdapterAddress(a: Integer): string;  

var  

NCB: TNCB; // Netbios control block //NetBios控制块  

ADAPTER: TADAPTERSTATUS; // Netbios adapter status//取网卡状态  

LANAENUM: TLANAENUM; // Netbios lana  

intIdx: Integer; // Temporary work value//临时变量  

cRC: Char; // Netbios return code//NetBios返回值  

strTemp: string; // Temporary string//临时变量  

begin  

// Initialize  

Result := '';  

try  

    // Zero control blocl  

    ZeroMemory(@NCB, SizeOf(NCB));  

    // Issue enum command  

    NCB.ncb_command := Chr(NCBENUM);  

    cRC := NetBios(@NCB);  

    // Reissue enum command  

    NCB.ncb_buffer := @LANAENUM;  

    NCB.ncb_length := SizeOf(LANAENUM);  

    cRC := NetBios(@NCB);  

    if Ord(cRC) <>  then  

      exit;  

    // Reset adapter  

    ZeroMemory(@NCB, SizeOf(NCB));  

    NCB.ncb_command := Chr(NCBRESET);  

    NCB.ncb_lana_num := LANAENUM.lana[a];  

    cRC := NetBios(@NCB);  

    if Ord(cRC) <>  then  

      exit;  

    // Get adapter address  

    ZeroMemory(@NCB, SizeOf(NCB));  

    NCB.ncb_command := Chr(NCBASTAT);  

    NCB.ncb_lana_num := LANAENUM.lana[a];  

    StrPCopy(NCB.ncb_callname, '*');  

    NCB.ncb_buffer := @ADAPTER;  

    NCB.ncb_length := SizeOf(ADAPTER);  

    cRC := NetBios(@NCB);  

    // Convert it to string  

    strTemp := '';  

    for intIdx :=  to  do  

      strTemp := strTemp + InttoHex(Integer(ADAPTER.adapter_address[intIdx]), );  

    Result := strTemp;  

finally  

end;  

end;  

//==========================================================================  

//取MAC地址(集成网卡和非集成网卡):  

function Getmac:string;  

var  

ncb : TNCB;  

s:string;  

adapt : TASTAT;  

lanaEnum : TLanaEnum;  

i, j, m : integer;  

strPart, strMac : string;  

begin  

FillChar(ncb, SizeOf(TNCB), );  

ncb.ncb_command := Char(NCBEnum);  

ncb.ncb_buffer := PChar(@lanaEnum);  

ncb.ncb_length := SizeOf(TLanaEnum);  

s:=Netbios(@ncb);  

for i :=  to integer(lanaEnum.length)- do  

begin  

    FillChar(ncb, SizeOf(TNCB), );  

    ncb.ncb_command := Char(NCBReset);  

    ncb.ncb_lana_num := lanaEnum.lana[i];  

    Netbios(@ncb);  

    Netbios(@ncb);  

    FillChar(ncb, SizeOf(TNCB), );  

    ncb.ncb_command := Chr(NCBAstat);  

    ncb.ncb_lana_num := lanaEnum.lana[i];  

    ncb.ncb_callname := '*               ';  

    ncb.ncb_buffer := PChar(@adapt);  

    ncb.ncb_length := SizeOf(TASTAT);  

    m:=;  

    if (Win32Platform = VER_PLATFORM_WIN32_NT) then  

    m:=;  

    if m= then  

    begin  

    if Netbios(@ncb) = Chr() then  

      strMac := '';  

      for j :=  to  do  

      begin  

        strPart := IntToHex(integer(adapt.adapter.adapter_address[j]), );  

        strMac := strMac + strPart + '-';  

      end;  

      SetLength(strMac, Length(strMac)-);  

    end;  

if m= then  

    if Netbios(@ncb) <> Chr() then  

    begin  

      strMac := '';  

      for j :=  to  do  

      begin  

        strPart := IntToHex(integer(adapt.adapter.adapter_address[j]), );  

        strMac := strMac + strPart + '-';  

      end;  

      SetLength(strMac, Length(strMac)-);  

    end;  

end;  

result:=strmac;  

end;  

function PartitionString(StrV,PrtSymbol: string): TStringList;  

var  

iTemp: integer;  

begin  

result := TStringList.Create;  

iTemp := pos(PrtSymbol,StrV);  

while iTemp> do begin  

    if iTemp> then result.Append(copy(StrV,,iTemp-));  

    delete(StrV,,iTemp+length(PrtSymbol)-);  

    iTemp := pos(PrtSymbol,StrV);  

end;  

if Strv<>'' then result.Append(StrV);  

end;  

function MacStr():String;  

var  

Str:TStrings;  

i:Integer;  

MacStr:String;  

begin  

MacStr:='';  

Str:=TStringList.Create;  

Str:=PartitionString(Getmac,'-');  

for i:= to Str.Count- do  

    MacStr:=MacStr+Str[i];  

Result:=MacStr;  

end;  

//==============================================  

//调用例子  

procedure TForm1.Button1Click(Sender: TObject);  

begin  

//Edit1.Text:=strpas(GetIdeSerialNumber)//取硬盘号  

//Edit1.text:=GetCPUIDStr;//CPU系列号  

//edit1.Text:=NBGetAdapterAddress();//非集成网卡  

Edit1.text:=MacStr;//集成和非集成网卡  

end;  

获取CPU系列号,硬盘系的更多相关文章

  1. Qt获取CPU编号和硬盘序列号

    windows下执行命令除了用cmd之外,还有个东西叫WMIC,非常强大,可以通过他获取很多信息,包括硬件信息. QString frmMain::getWMIC(const QString & ...

  2. C#获取CPU与网卡硬盘序列号及Base64和DES加密解密操作类

    public class RegisterHelp { /// <summary> /// CPU /// </summary> /// <returns>< ...

  3. 取CPU序列号,获取网卡,取硬盘系列号,获取目录下的文件,强制删除目录

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  4. C#获取cpu序列号 硬盘ID 网卡硬地址以及操作注册表 .

    转:http://blog.csdn.net/smartsmile2012/article/details/8682295 #region 获取cpu序列号 硬盘ID 网卡硬地址 /**/ /// & ...

  5. C# 使用 PerformanceCounter 获取 CPU 和 硬盘的使用率

    C# 使用 PerformanceCounter 获取 CPU 和 硬盘的使用率: 先看界面: 建一个 Windows Form  桌面程序,代码如下: using System; using Sys ...

  6. C# 获取CPU序列号、网卡MAC地址、硬盘序列号封装类,用于软件绑定电脑

    using System.Management; namespace GLaLa { /// <summary> /// hardware_mac 的摘要说明. /// </summ ...

  7. C# 获取电脑MAC地址,IP地址,物理内存,CPU序列号,硬盘ID..........................

    上班很忙,自己做个记录 代码如下: 需要引入:System.Management 代码如下: using System; using System.Collections.Generic; using ...

  8. 获取CPU序列号、网卡MAC地址、硬盘序列号

    <pre name="code" class="csharp"> using System; using System.Collections; u ...

  9. Golang获取CPU、内存、硬盘使用率

    Golang获取CPU.内存.硬盘使用率 工具包 go get github.com/shirou/gopsutil 实现 func GetCpuPercent() float64 { percent ...

随机推荐

  1. Android------自定义ListView详解

    引自:http://www.cnblogs.com/phonegap/archive/2011/04/28/2535732.html 在这里我就对自定义ListView进行讲解下吧,直入真题吧,首先我 ...

  2. Android之TextView控件的学习

    <TextView android:id="@+id/tv"             //id号,指明这个TextView的唯一身份 android:autoLink=&qu ...

  3. line-box(转)

    inline-block是什么? Inline-block是元素display属性的一个值.这个名字的由来是因为,display设置这个值的元素,兼具行内元素( inline elements)跟块级 ...

  4. 关于css的伪类和伪元素

    现在才发现自己一直没有分清楚css的伪类和伪元素啊,so,总结一下. CSS 伪类用于向某些选择器添加特殊的效果. CSS 伪元素用于将特殊的效果添加到某些选择器. 可以明确两点,第一两者都与选择器相 ...

  5. extjs入门

    http://blog.csdn.net/xiebaochun/article/details/36414437

  6. Init.rc分析(刘举奎)

    http://www.360doc.com/content/14/0926/20/13253385_412582822.shtml

  7. Persistent Bookcase

    Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input standard ...

  8. Android apk反编译基础(apktoos)图文教程

    本文主要介绍了Android apk反编译基础,使用的工具是apktoos,我们将用图文的方式说明apktoos工具的使用方式,你可以参考这个方法反编译其它APK试试看了 很久有写过一个广工图书馆主页 ...

  9. CodeForces 621B Wet Shark and Bishops

    记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...

  10. Mariadb galera 群集

    环境:  CentOS 7 x64  *  3 IP : 192.168.0.100 IP : 192.168.0.101 IP : 192.168.0.102 配置mariadb YUM 源 htt ...