紧急求助!15(15分)

  • 主题发起人 主题发起人 fenyun61
  • 开始时间 开始时间
F

fenyun61

Unregistered / Unconfirmed
GUEST, unregistred user!
那位大虾能给出一些读取硬盘序列号的api函数,要求读出的是<br>硬盘固有的序列号。<br>最好详细一些,急用!<br>谢谢!<br>哪为对这方面有研究,可以联系你吗,比如:qq。
 
function GetIdeDiskSerialNumber : String;<br>type<br>&nbsp; TSrbIoControl = packed record<br>&nbsp; &nbsp; HeaderLength : ULONG;<br>&nbsp; &nbsp; Signature &nbsp; &nbsp;: Array[0..7] of Char;<br>&nbsp; &nbsp; Timeout &nbsp; &nbsp; &nbsp;: ULONG;<br>&nbsp; &nbsp; ControlCode &nbsp;: ULONG;<br>&nbsp; &nbsp; ReturnCode &nbsp; : ULONG;<br>&nbsp; &nbsp; Length &nbsp; &nbsp; &nbsp; : ULONG;<br>&nbsp; end;<br>&nbsp; SRB_IO_CONTROL = TSrbIoControl;<br>&nbsp; PSrbIoControl = ^TSrbIoControl;<br><br>&nbsp; TIDERegs = packed record<br>&nbsp; &nbsp; bFeaturesReg &nbsp; &nbsp; : Byte; // Used for specifying SMART "commands".<br>&nbsp; &nbsp; bSectorCountReg &nbsp;: Byte; // IDE sector count register<br>&nbsp; &nbsp; bSectorNumberReg : Byte; // IDE sector number register<br>&nbsp; &nbsp; bCylLowReg &nbsp; &nbsp; &nbsp; : Byte; // IDE low order cylinder value<br>&nbsp; &nbsp; bCylHighReg &nbsp; &nbsp; &nbsp;: Byte; // IDE high order cylinder value<br>&nbsp; &nbsp; bDriveHeadReg &nbsp; &nbsp;: Byte; // IDE drive/head register<br>&nbsp; &nbsp; bCommandReg &nbsp; &nbsp; &nbsp;: Byte; // Actual IDE command.<br>&nbsp; &nbsp; bReserved &nbsp; &nbsp; &nbsp; &nbsp;: Byte; // reserved for future use. &nbsp;Must be zero.<br>&nbsp; end;<br>&nbsp; IDEREGS &nbsp; = TIDERegs;<br>&nbsp; PIDERegs &nbsp;= ^TIDERegs;<br><br>&nbsp; TSendCmdInParams = packed record<br>&nbsp; &nbsp; cBufferSize &nbsp;: DWORD; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Buffer size in bytes<br>&nbsp; &nbsp; irDriveRegs &nbsp;: TIDERegs; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Structure with drive register values.<br>&nbsp; &nbsp; bDriveNumber : Byte; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Physical drive number to send command to (0,1,2,3).<br>&nbsp; &nbsp; bReserved &nbsp; &nbsp;: Array[0..2] of Byte; &nbsp;// Reserved for future expansion.<br>&nbsp; &nbsp; dwReserved &nbsp; : Array[0..3] of DWORD; // For future use.<br>&nbsp; &nbsp; bBuffer &nbsp; &nbsp; &nbsp;: Array[0..0] of Byte; &nbsp;// Input buffer.<br>&nbsp; end;<br>&nbsp; SENDCMDINPARAMS &nbsp; = TSendCmdInParams;<br>&nbsp; PSendCmdInParams &nbsp;= ^TSendCmdInParams;<br><br>&nbsp; TIdSector = packed record<br>&nbsp; &nbsp; wGenConfig &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; wNumCyls &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; wReserved &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; wNumHeads &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; wBytesPerTrack &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; wBytesPerSector &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; wSectorsPerTrack &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; wVendorUnique &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Array[0..2] of Word;<br>&nbsp; &nbsp; sSerialNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Array[0..19] of Char;<br>&nbsp; &nbsp; wBufferType &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; wBufferSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; wECCSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; sFirmwareRev &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Array[0..7] of Char;<br>&nbsp; &nbsp; sModelNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Array[0..39] of Char;<br>&nbsp; &nbsp; wMoreVendorUnique &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; wDoubleWordIO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; wCapabilities &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; wReserved1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; wPIOTiming &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; wDMATiming &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; wBS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; wNumCurrentCyls &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; wNumCurrentHeads &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; wNumCurrentSectorsPerTrack : Word;<br>&nbsp; &nbsp; ulCurrentSectorCapacity &nbsp; &nbsp;: ULONG;<br>&nbsp; &nbsp; wMultSectorStuff &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; ulTotalAddressableSectors &nbsp;: ULONG;<br>&nbsp; &nbsp; wSingleWordDMA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Word;<br>&nbsp; &nbsp; wMultiWordDMA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Word;<br>&nbsp; &nbsp; bReserved &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Array[0..127] of Byte;<br>&nbsp; end;<br>&nbsp; PIdSector = ^TIdSector;<br><br>const<br>&nbsp; IDE_ID_FUNCTION = $EC;<br>&nbsp; IDENTIFY_BUFFER_SIZE &nbsp; &nbsp; &nbsp; = 512;<br>&nbsp; DFP_RECEIVE_DRIVE_DATA &nbsp; &nbsp; &nbsp; &nbsp;= $0007c088;<br>&nbsp; IOCTL_SCSI_MINIPORT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = $0004d008;<br>&nbsp; IOCTL_SCSI_MINIPORT_IDENTIFY &nbsp;= $001b0501;<br>&nbsp; DataSize = sizeof(TSendCmdInParams)-1+IDENTIFY_BUFFER_SIZE;<br>&nbsp; BufferSize = SizeOf(SRB_IO_CONTROL)+DataSize;<br>&nbsp; W9xBufferSize = IDENTIFY_BUFFER_SIZE+16;<br>var<br>&nbsp; hDevice : THandle;<br>&nbsp; cbBytesReturned : DWORD;<br>&nbsp; pInData : PSendCmdInParams;<br>&nbsp; pOutData : Pointer; // PSendCmdInParams;<br>&nbsp; Buffer : Array[0..BufferSize-1] of Byte;<br>&nbsp; srbControl : TSrbIoControl absolute Buffer;<br><br>&nbsp; procedure ChangeByteOrder( var Data; Size : Integer );<br>&nbsp; var ptr : PChar;<br>&nbsp; &nbsp; &nbsp; i : Integer;<br>&nbsp; &nbsp; &nbsp; c : Char;<br>&nbsp; begin<br>&nbsp; &nbsp; ptr := @Data;<br>&nbsp; &nbsp; for i := 0 to (Size shr 1)-1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; c := ptr^;<br>&nbsp; &nbsp; &nbsp; ptr^ := (ptr+1)^;<br>&nbsp; &nbsp; &nbsp; (ptr+1)^ := c;<br>&nbsp; &nbsp; &nbsp; Inc(ptr,2);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br><br>begin<br>&nbsp; Result := '';<br>&nbsp; FillChar(Buffer,BufferSize,#0);<br>&nbsp; if Win32Platform=VER_PLATFORM_WIN32_NT then<br>&nbsp; &nbsp; begin // Windows NT, Windows 2000<br>&nbsp; &nbsp; &nbsp; // Get SCSI port handle<br>&nbsp; &nbsp; &nbsp; hDevice := CreateFile( '//./Scsi0:', GENERIC_READ or GENERIC_WRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0 );<br>&nbsp; &nbsp; &nbsp; if hDevice=INVALID_HANDLE_VALUE then Exit;<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; srbControl.HeaderLength := SizeOf(SRB_IO_CONTROL);<br>&nbsp; &nbsp; &nbsp; &nbsp; System.Move('SCSIDISK',srbControl.Signature,8);<br>&nbsp; &nbsp; &nbsp; &nbsp; srbControl.Timeout &nbsp; &nbsp; &nbsp;:= 2;<br>&nbsp; &nbsp; &nbsp; &nbsp; srbControl.Length &nbsp; &nbsp; &nbsp; := DataSize;<br>&nbsp; &nbsp; &nbsp; &nbsp; srbControl.ControlCode &nbsp;:= IOCTL_SCSI_MINIPORT_IDENTIFY;<br>&nbsp; &nbsp; &nbsp; &nbsp; pInData := PSendCmdInParams(PChar(@Buffer)+SizeOf(SRB_IO_CONTROL));<br> pOutData := pInData;<br>&nbsp; &nbsp; &nbsp; &nbsp; with pInData^ do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cBufferSize &nbsp;:= IDENTIFY_BUFFER_SIZE;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bDriveNumber := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with irDriveRegs do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bFeaturesReg &nbsp; &nbsp; := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bSectorCountReg &nbsp;:= 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bSectorNumberReg := 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bCylLowReg &nbsp; &nbsp; &nbsp; := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bCylHighReg &nbsp; &nbsp; &nbsp;:= 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bDriveHeadReg &nbsp; &nbsp;:= $A0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bCommandReg &nbsp; &nbsp; &nbsp;:= IDE_ID_FUNCTION;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; if not DeviceIoControl( hDevice, IOCTL_SCSI_MINIPORT, @Buffer, BufferSize, @Buffer, BufferSize, cbBytesReturned, nil ) then Exit;<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hDevice);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; begin // Windows 95 OSR2, Windows 98<br>&nbsp; &nbsp; &nbsp; hDevice := CreateFile( '//./SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0 );<br>&nbsp; &nbsp; &nbsp; if hDevice=INVALID_HANDLE_VALUE then Exit;<br> try<br>&nbsp; &nbsp; &nbsp; pInData := PSendCmdInParams(@Buffer);<br> pOutData := PChar(@pInData^.bBuffer);<br>&nbsp; &nbsp; &nbsp; with pInData^ do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; cBufferSize &nbsp;:= IDENTIFY_BUFFER_SIZE;<br>&nbsp; &nbsp; &nbsp; &nbsp; bDriveNumber := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; with irDriveRegs do<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bFeaturesReg &nbsp; &nbsp; := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bSectorCountReg &nbsp;:= 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bSectorNumberReg := 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bCylLowReg &nbsp; &nbsp; &nbsp; := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bCylHighReg &nbsp; &nbsp; &nbsp;:= 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bDriveHeadReg &nbsp; &nbsp;:= $A0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bCommandReg &nbsp; &nbsp; &nbsp;:= IDE_ID_FUNCTION;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if not DeviceIoControl( hDevice, DFP_RECEIVE_DRIVE_DATA, pInData, SizeOf(TSendCmdInParams)-1, pOutData, W9xBufferSize, cbBytesReturned, nil ) then Exit;<br> finally<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hDevice);<br> end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; with PIdSector(PChar(pOutData)+16)^ do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ChangeByteOrder(sSerialNumber,SizeOf(sSerialNumber));<br>&nbsp; &nbsp; &nbsp; SetString(Result,sSerialNumber,SizeOf(sSerialNumber));<br>&nbsp; &nbsp; end;<br>&nbsp; result:=trim(result);<br>&nbsp; // &nbsp;Win95 98 要先将system下的SMARTVSD.VXD 必须安装到 /windows/system/iosubsys<br>&nbsp; // &nbsp;并在复制后重新启动系统<br>end;
 

Similar threads

回复
0
查看
711
不得闲
D
回复
0
查看
625
DelphiTeacher的专栏
D
D
回复
0
查看
848
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部