注意:
1.不是逻辑序列号
2.不是用delphi来调用其它语言写的dll实理

解决方案 »

  1.   

    to: comerliang(天地良心
    给个代码好吗,谢谢啦!
      

  2.   

    to:comanche(太可怕
    插入几句汇编  也可以!
      

  3.   

    function GetIdeSerialNumber: pchar;
      const IDENTIFY_BUFFER_SIZE = 512;
    type
       TIDERegs = packed record
         bFeaturesReg: BYTE; // Used for specifying SMART "commands".
         bSectorCountReg: BYTE; // IDE sector count register
         bSectorNumberReg: BYTE; // IDE sector number register
         bCylLowReg: BYTE; // IDE low order cylinder value
         bCylHighReg: BYTE; // IDE high order cylinder value
         bDriveHeadReg: BYTE; // IDE drive/head register
         bCommandReg: BYTE; // Actual IDE command.
         bReserved: BYTE; // reserved for future use. Must be zero.
      end;
      TSendCmdInParams = packed record
        // Buffer size in bytes
        cBufferSize: DWORD;
        // Structure with drive register values.
        irDriveRegs: TIDERegs;
        // Physical drive number to send command to (0,1,2,3).
        bDriveNumber: BYTE;
        bReserved: array[0..2] of Byte;
        dwReserved: array[0..3] of DWORD;
        bBuffer: array[0..0] of Byte; // Input buffer.
      end;
      TIdSector = packed record
        wGenConfig: Word;
        wNumCyls: Word;
        wReserved: Word;
        wNumHeads: Word;
        wBytesPerTrack: Word;
        wBytesPerSector: Word;
        wSectorsPerTrack: Word;
        wVendorUnique: array[0..2] of Word;
        sSerialNumber: array[0..19] of CHAR;
        wBufferType: Word;
        wBufferSize: Word;
        wECCSize: Word;
        sFirmwareRev: array[0..7] of Char;
        sModelNumber: array[0..39] 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[0..127] of BYTE;
      end;
      PIdSector = ^TIdSector;
      TDriverStatus = packed record
        // 驱动器返回的错误代码,无错则返回0
        bDriverError: Byte;
        // IDE出错寄存器的内容,只有当bDriverError 为 SMART_IDE_ERROR 时有效
        bIDEStatus: Byte;
        bReserved: array[0..1] of Byte;
        dwReserved: array[0..1] of DWORD;
      end;
      TSendCmdOutParams = packed record
        // bBuffer的大小
        cBufferSize: DWORD;
        // 驱动器状态
        DriverStatus: TDriverStatus;
        // 用于保存从驱动器读出的数据的缓冲区,实际长度由cBufferSize决定
        bBuffer: array[0..0] of BYTE;
      end;
    var
      hDevice: Thandle;
      cbBytesReturned: DWORD;
      SCIP: TSendCmdInParams;
      aIdOutCmd: array[0..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE-1)-1] of Byte;
      IdOutCmd: TSendCmdOutParams absolute aIdOutCmd;
    procedure ChangeByteOrder(var Data; Size: Integer);
    var
      ptr: Pchar;
      i: Integer;
      c: Char;
    begin
      ptr := @Data;
      for I := 0 to (Size shr 1) - 1 do begin
        c := ptr^;
        ptr^ := (ptr + 1)^;
        (ptr + 1)^ := c;
        Inc(ptr, 2);
      end;
    end;
    begin
    Result := ''; // 如果出错则返回空串
    if SysUtils.Win32Platform = VER_PLATFORM_WIN32_NT then begin // Windows NT, Windows 2000
    // 提示! 改变名称可适用于其它驱动器,如第二个驱动器: '\\.\PhysicalDrive1\'
    hDevice := CreateFile('\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,
    FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
    end else // Version Windows 95 OSR2, Windows 98
    hDevice := CreateFile('\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0);
    if hDevice = INVALID_HANDLE_VALUE then Exit;
    try
    FillChar(SCIP, SizeOf(TSendCmdInParams) - 1, #0);
    FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #0);
    cbBytesReturned := 0;
    // Set up data structures for IDENTIFY command.
    with SCIP do begin
    cBufferSize := IDENTIFY_BUFFER_SIZE;
    // bDriveNumber := 0;
    with irDriveRegs do begin
    bSectorCountReg := 1;
    bSectorNumberReg := 1;
    // if Win32Platform=VER_PLATFORM_WIN32_NT then bDriveHeadReg := $A0
    // else bDriveHeadReg := $A0 or ((bDriveNum and 1) shl 4);
    bDriveHeadReg := $A0;
    bCommandReg := $EC;
    end;
    end;
    if not DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - 1,
    @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))^:= #0;
    Result := Pchar(@sSerialNumber);
    end;
    end;//调用方法
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Edit1.Text:=strpas(GetIdeSerialNumber);
    end;
      

  4.   

    如果要加密么把CPU的也给你不过有汇编:
    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 GetCPUIDStr:String;
    var
      CPUID:TCPUID;
    begin
      CPUID:=GetCPUID;
      Result:=IntToHex(CPUID[1],8)+IntToHex(CPUID[2],8)+IntToHex(CPUID[3],8)+IntToHex(CPUID[4],8);
    end;
      

  5.   

    to: ksaiy(消失在人海) 
    是否对所有硬盘有效?
      

  6.   

    to: ksaiy(消失在人海) 
    我是想做注册软件用
    能读出所有的cpu 号吗?行不行
      

  7.   

    CPU和硬盘系列号一起生成系列号:
    function GetID:String;
    var
      Str:String;
      LenIDNmuber,i:Integer;
      a,sum:LongWord;
    begin
    sum:=0;
    Str:=strpas(GetIdeSerialNumber)+GetCPUIDStr;
    LenIDNmuber:=Length(Str);
    if LenIDNmuber>0 then
      begin
        for i:=1 to LenIDNmuber do
          begin
            a:=ord(Str[i]) shl $11;
            sum:=sum+a;
          end;
        result:=IntToStr(sum);
      end;  
    end;
      

  8.   

    楼上的找到了哈, 就是那段, 刚才找 google 找了半天
      

  9.   

    同一系列的CPUID是一样的.硬盘系列也一样.
    如果怕有相同的系列号.你可以在其中增加一个随机的值.这样出现重复的机会就很少了。
    这里有个一个加密的模块例子.你可以下载看一下.
    www.ksaiy.com/ynen
      

  10.   

    to : ksaiy(消失在人海)
    这一句:
    Str:=strpas(GetIdeSerialNumber)+GetCPUIDStr;如果用户format了硬盘,这个号就变了,注册码就不对了,怎么解决?
      

  11.   

    其实你要加密考虑的问题还很多。生成系列号只是其中的一小部分.还有很多问题你要解决呢.比如采用的加密算法、反跟踪技术、程序自校验、软件加壳等等,还有采用的注册方式是注册码?还是keyfile保护,还有就是网络验证,还有就是你是否要选择加密狗。等等。
      

  12.   

    读取硬盘的物理序列号//获得硬盘序列号
    function GetIdeSerialNumber() : PChar; stdcall;
    const
      IDENTIFY_BUFFER_SIZE = 512;
    type
      TIDERegs = packed record
         bFeaturesReg: BYTE; // Used for specifying SMART "commands".
         bSectorCountReg: BYTE; // IDE sector count register
         bSectorNumberReg: BYTE; // IDE sector number register
         bCylLowReg: BYTE; // IDE low order cylinder value
         bCylHighReg: BYTE; // IDE high order cylinder value
         bDriveHeadReg: BYTE; // IDE drive/head register
         bCommandReg: BYTE; // Actual IDE command.
         bReserved: BYTE; // reserved for future use. Must be zero.
      end;  TSendCmdInParams = packed record
        // Buffer size in bytes
        cBufferSize: DWORD;
        // Structure with drive register values.
        irDriveRegs: TIDERegs;
        // Physical drive number to send command to (0,1,2,3).
        bDriveNumber: BYTE;
        bReserved: array[0..2] of Byte;
        dwReserved: array[0..3] of DWORD;
        bBuffer: array[0..0] of Byte; // Input buffer.
      end;  TIdSector = packed record
        wGenConfig: Word;
        wNumCyls: Word;
        wReserved: Word;
        wNumHeads: Word;
        wBytesPerTrack: Word;
        wBytesPerSector: Word;
        wSectorsPerTrack: Word;
        wVendorUnique: array[0..2] of Word;
        sSerialNumber: array[0..19] of CHAR;
        wBufferType: Word;
        wBufferSize: Word;
        wECCSize: Word;
        sFirmwareRev: array[0..7] of Char;
        sModelNumber: array[0..39] 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[0..127] of BYTE;
      end;  PIdSector = ^TIdSector;  TDriverStatus = packed record
        // 驱动器返回的错误代码,无错则返回0
        bDriverError: Byte;
        // IDE出错寄存器的内容,只有当bDriverError 为 SMART_IDE_ERROR 时有效
        bIDEStatus: Byte;
        bReserved: array[0..1] of Byte;
        dwReserved: array[0..1] of DWORD;
      end;  TSendCmdOutParams = packed record
        // bBuffer的大小
        cBufferSize: DWORD;
        // 驱动器状态
        DriverStatus: TDriverStatus;
        // 用于保存从驱动器读出的数据的缓冲区,实际长度由cBufferSize决定
        bBuffer: array[0..0] of BYTE;
      end;
    var
      hDevice : THandle;
      cbBytesReturned : DWORD;
      SCIP : TSendCmdInParams;
      aIdOutCmd : array[0..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE - 1) - 1] of Byte;
      IdOutCmd : TSendCmdOutParams absolute aIdOutCmd;  procedure ChangeByteOrder(var Data; Size: Integer);
      var
        ptr : PChar;
        i : Integer;
        c : Char;
      begin
        ptr := @Data;    for I := 0 to (Size shr 1) - 1 do
        begin
          c := ptr^;
          ptr^ := (ptr + 1)^;
          (ptr + 1)^ := c;
          Inc(ptr, 2);
        end;
      end;
    begin
      Result := ''; // 如果出错则返回空串  if SysUtils.Win32Platform = VER_PLATFORM_WIN32_NT then  // Windows NT, Windows 2000
      begin
        // 提示! 改变名称可适用于其它驱动器,如第二个驱动器: '\\.\PhysicalDrive1\'
        hDevice := CreateFile('\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,
                              FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
      end
      else // Version Windows 95 OSR2, Windows 98
        hDevice := CreateFile('\\.\SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0);    if hDevice = INVALID_HANDLE_VALUE then Exit;    try
          FillChar(SCIP, SizeOf(TSendCmdInParams) - 1, #0);
          FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #0);
          cbBytesReturned := 0;      // Set up data structures for IDENTIFY command.
          with SCIP do
          begin
            cBufferSize := IDENTIFY_BUFFER_SIZE;        // bDriveNumber := 0;
            with irDriveRegs do
            begin
              bSectorCountReg := 1;
              bSectorNumberReg := 1;          // if Win32Platform=VER_PLATFORM_WIN32_NT then bDriveHeadReg := $A0
              // else bDriveHeadReg := $A0 or ((bDriveNum and 1) shl 4);
              bDriveHeadReg := $A0;
              bCommandReg := $EC;
            end;
          end;      if not DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - 1,
                                @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))^ := #0;      Result := Pchar(@sSerialNumber);      end;
    end;
      

  13.   

    其实你要加密考虑的问题还很多。生成系列号只是其中的一小部分.还有很多问题你要解决呢.比如采用的加密算法、反跟踪技术、程序自校验、软件加壳等等,还有采用的注册方式是注册码?还是keyfile保护,还有就是网络验证,还有就是你是否要选择加密狗。等等。
      

  14.   

    谢谢大家,特别是ksaiy(消失在人海) ( 
    但是我用c#的方法读取物理号和你的这个代码,两个号不一样?为什么?哪一个是对的?c#代码:
    String HDid;
    ManagementClass cimobject = new ManagementClass("Win32_DiskDrive");
    ManagementObjectCollection moc = cimobject.GetInstances();
    foreach(ManagementObject mo in moc)
    {
    HDid = (string)mo.Properties["Model"].Value;
    MessageBox.Show(HDid ); 
    }
      

  15.   

    C#的我没有试过。我用VC写的代码和我用DELPHI的代码得到的是一样的硬盘系列号。
      

  16.   

    现在我做了一个DLL。我用的时候是直接调用的。在C#中我也是直接调用我的DLL
      

  17.   

    to: ksaiy(消失在人海) 
    哪你的GetIdeSerialNumber取出是否会有重复
      

  18.   

    要加个什么单元、[Error] Unit1.pas(168): Undeclared identifier: 'TCPUID'
      

  19.   

    一块硬盘不会有有重复的.
    如果相同型号的多块硬盘就会有重复的.
    所以在使用的时候我建议你和CPUID一起使用。同时增加一个随机值....
      

  20.   

    type
      TCPUID= array[1..4] of Longint;
      

  21.   

    取序列号(CPU,硬盘,网卡)控件下载:
    Http://www.datcn.com/downloads/hardwareinfo.exe