|
 |
栏目导栏 |
|
| |
|
|
|
|
 |
资料搜索 |
|
| |
|
|
|
|
 |
热门文章 |
|
| |
|
|
|
|
 |
最新文章 |
|
| |
|
|
|
| |
| |
|
|
|
|
如何得到硬盘物理序号ZNMLinux联盟 ZNMLinux联盟 ZNMLinux联盟
unit hdid;ZNMLinux联盟 ZNMLinux联盟 interfaceZNMLinux联盟 ZNMLinux联盟 usesZNMLinux联盟 Windows, Controls,SysUtils,Forms;ZNMLinux联盟 //, Graphics, Dialogs, Classes, Messages,StdCtrls;ZNMLinux联盟 typeZNMLinux联盟 TSrbIoControl = packed recordZNMLinux联盟 HeaderLength : ULONG;ZNMLinux联盟 Signature : Array[0..7] of Char;ZNMLinux联盟 Timeout : ULONG;ZNMLinux联盟 ControlCode : ULONG;ZNMLinux联盟 ReturnCode : ULONG;ZNMLinux联盟 Length : ULONG;ZNMLinux联盟 end;ZNMLinux联盟 SRB_IO_CONTROL = TSrbIoControl;ZNMLinux联盟 PSrbIoControl = ^TSrbIoControl;ZNMLinux联盟 ZNMLinux联盟 TIDERegs = packed recordZNMLinux联盟 bFeaturesReg : Byte; // Used for specifying SMART "commands".ZNMLinux联盟 bSectorCountReg : Byte; // IDE sector count registerZNMLinux联盟 bSectorNumberReg : Byte; // IDE sector number registerZNMLinux联盟 bCylLowReg : Byte; // IDE low order cylinder valueZNMLinux联盟 bCylHighReg : Byte; // IDE high order cylinder valueZNMLinux联盟 bDriveHeadReg : Byte; // IDE drive/head registerZNMLinux联盟 bCommandReg : Byte; // Actual IDE command.ZNMLinux联盟 bReserved : Byte; // reserved. Must be zero.ZNMLinux联盟 end;ZNMLinux联盟 IDEREGS = TIDERegs;ZNMLinux联盟 PIDERegs = ^TIDERegs;ZNMLinux联盟 ZNMLinux联盟 TSendCmdInParams = packed recordZNMLinux联盟 cBufferSize : DWORD;ZNMLinux联盟 irDriveRegs : TIDERegs;ZNMLinux联盟 bDriveNumber : Byte;ZNMLinux联盟 bReserved : Array[0..2] of Byte;ZNMLinux联盟 dwReserved : Array[0..3] of DWORD;ZNMLinux联盟 bBuffer : Array[0..0] of Byte;ZNMLinux联盟 end;ZNMLinux联盟 SENDCMDINPARAMS = TSendCmdInParams;ZNMLinux联盟 PSendCmdInParams = ^TSendCmdInParams;ZNMLinux联盟 ZNMLinux联盟 TIdSector = packed recordZNMLinux联盟 wGenConfig : Word;ZNMLinux联盟 wNumCyls : Word;ZNMLinux联盟 wReserved : Word;ZNMLinux联盟 wNumHeads : Word;ZNMLinux联盟 wBytesPerTrack : Word;ZNMLinux联盟 wBytesPerSector : Word;ZNMLinux联盟 wSectorsPerTrack : Word;ZNMLinux联盟 wVendorUnique : Array[0..2] of Word;ZNMLinux联盟 sSerialNumber : Array[0..19] of Char;ZNMLinux联盟 wBufferType : Word;ZNMLinux联盟 wBufferSize : Word;ZNMLinux联盟 wECCSize : Word;ZNMLinux联盟 sFirmwareRev : Array[0..7] of Char;ZNMLinux联盟 sModelNumber : Array[0..39] of Char;ZNMLinux联盟 wMoreVendorUnique : Word;ZNMLinux联盟 wDoubleWordIO : Word;ZNMLinux联盟 wCapabilities : Word;ZNMLinux联盟 wReserved1 : Word;ZNMLinux联盟 wPIOTiming : Word;ZNMLinux联盟 wDMATiming : Word;ZNMLinux联盟 wBS : Word;ZNMLinux联盟 wNumCurrentCyls : Word;ZNMLinux联盟 wNumCurrentHeads : Word;ZNMLinux联盟 wNumCurrentSectorsPerTrack : Word;ZNMLinux联盟 ulCurrentSectorCapacity : ULONG;ZNMLinux联盟 wMultSectorStuff : Word;ZNMLinux联盟 ulTotalAddressableSectors : ULONG;ZNMLinux联盟 wSingleWordDMA : Word;ZNMLinux联盟 wMultiWordDMA : Word;ZNMLinux联盟 bReserved : Array[0..127] of Byte;ZNMLinux联盟 end;ZNMLinux联盟 PIdSector = ^TIdSector;ZNMLinux联盟 ZNMLinux联盟 constZNMLinux联盟 IDE_ID_FUNCTION = $EC;ZNMLinux联盟 IDENTIFY_BUFFER_SIZE = 512;ZNMLinux联盟 DFP_RECEIVE_DRIVE_DATA = {ARTICLE_CONTENT}07c088;ZNMLinux联盟 IOCTL_SCSI_MINIPORT = {ARTICLE_CONTENT}04d008;ZNMLinux联盟 IOCTL_SCSI_MINIPORT_IDENTIFY = {ARTICLE_CONTENT}1b0501;ZNMLinux联盟 DataSize = sizeof(TSendCmdInParams)-1+IDENTIFY_BUFFER_SIZE;ZNMLinux联盟 BufferSize = SizeOf(SRB_IO_CONTROL)+DataSize;ZNMLinux联盟 W9xBufferSize = IDENTIFY_BUFFER_SIZE+16;ZNMLinux联盟 typeZNMLinux联盟 Thdidform = class(TForm)ZNMLinux联盟 privateZNMLinux联盟 { Private declarations }ZNMLinux联盟 publicZNMLinux联盟 ZNMLinux联盟 { Public declarations }ZNMLinux联盟 end;ZNMLinux联盟 ZNMLinux联盟 varZNMLinux联盟 hdidform: Thdidform;ZNMLinux联盟 function GetIdeDiskSerialNumber : String;ZNMLinux联盟 ZNMLinux联盟 implementationZNMLinux联盟 ZNMLinux联盟 {$R *.DFM}ZNMLinux联盟 procedure ChangeByteOrder( var Data; Size : Integer );ZNMLinux联盟 var ptr : PChar;ZNMLinux联盟 i : Integer;ZNMLinux联盟 c : Char;ZNMLinux联盟 beginZNMLinux联盟 ptr := @Data;ZNMLinux联盟 for i := 0 to (Size shr 1)-1 doZNMLinux联盟 beginZNMLinux联盟 c := ptr^;ZNMLinux联盟 ptr^ := (ptr+1)^;ZNMLinux联盟 (ptr+1)^ := c;ZNMLinux联盟 Inc(ptr,2);ZNMLinux联盟 end;ZNMLinux联盟 end;ZNMLinux联盟 ZNMLinux联盟 function GetIdeDiskSerialNumber : String;ZNMLinux联盟 ZNMLinux联盟 varZNMLinux联盟 hDevice : THandle;ZNMLinux联盟 cbBytesReturned : DWORD;ZNMLinux联盟 pInData : PSendCmdInParams;ZNMLinux联盟 pOutData : Pointer; // PSendCmdOutParamsZNMLinux联盟 Buffer : Array[0..BufferSize-1] of Byte;ZNMLinux联盟 srbControl : TSrbIoControl absolute Buffer;ZNMLinux联盟 beginZNMLinux联盟 Result := '';ZNMLinux联盟 FillChar(Buffer,BufferSize,#0);ZNMLinux联盟 if Win32Platform=VER_PLATFORM_WIN32_NT thenZNMLinux联盟 begin // Windows NT, Windows 2000ZNMLinux联盟 // Get SCSI port handleZNMLinux联盟 hDevice := CreateFile( '.Scsi0:',ZNMLinux联盟 GENERIC_READ or GENERIC_WRITE,ZNMLinux联盟 FILE_SHARE_READ or FILE_SHARE_WRITE,ZNMLinux联盟 nil, OPEN_EXISTING, 0, 0 );ZNMLinux联盟 if hDevice=INVALID_HANDLE_VALUE then Exit;ZNMLinux联盟 tryZNMLinux联盟 srbControl.HeaderLength := SizeOf(SRB_IO_CONTROL);ZNMLinux联盟 System.Move('SCSIDISK',srbControl.Signature,8);ZNMLinux联盟 srbControl.Timeout := 2;ZNMLinux联盟 srbControl.Length := DataSize;ZNMLinux联盟 srbControl.ControlCode := IOCTL_SCSI_MINIPORT_IDENTIFY;ZNMLinux联盟 pInData := PSendCmdInParams(PChar(@Buffer)ZNMLinux联盟 +SizeOf(SRB_IO_CONTROL));ZNMLinux联盟 pOutData := pInData;ZNMLinux联盟 with pInData^ doZNMLinux联盟 beginZNMLinux联盟 cBufferSize := IDENTIFY_BUFFER_SIZE;ZNMLinux联盟 bDriveNumber := 0;ZNMLinux联盟 with irDriveRegs doZNMLinux联盟 beginZNMLinux联盟 bFeaturesReg := 0;ZNMLinux联盟 bSectorCountReg := 1;ZNMLinux联盟 bSectorNumberReg := 1;ZNMLinux联盟 bCylLowReg := 0;ZNMLinux联盟 bCylHighReg := 0;ZNMLinux联盟 bDriveHeadReg := $A0;ZNMLinux联盟 bCommandReg := IDE_ID_FUNCTION;ZNMLinux联盟 end;ZNMLinux联盟 end;ZNMLinux联盟 if not DeviceIoControl( hDevice, IOCTL_SCSI_MINIPORT,ZNMLinux联盟 @Buffer, BufferSize, @Buffer, BufferSize,ZNMLinux联盟 cbBytesReturned, nil ) then Exit;ZNMLinux联盟 finallyZNMLinux联盟 CloseHandle(hDevice);ZNMLinux联盟 end;ZNMLinux联盟 endZNMLinux联盟 elseZNMLinux联盟 begin // Windows 95 OSR2, Windows 98ZNMLinux联盟 hDevice := CreateFile( '.SMARTVSD', 0, 0, nil,ZNMLinux联盟 CREATE_NEW, 0, 0 );ZNMLinux联盟 if hDevice=INVALID_HANDLE_VALUE then Exit;ZNMLinux联盟 tryZNMLinux联盟 pInData := PSendCmdInParams(@Buffer);ZNMLinux联盟 pOutData := @pInData^.bBuffer;ZNMLinux联盟 with pInData^ doZNMLinux联盟 beginZNMLinux联盟 cBufferSize := IDENTIFY_BUFFER_SIZE;ZNMLinux联盟 bDriveNumber := 0;ZNMLinux联盟 with irDriveRegs doZNMLinux联盟 beginZNMLinux联盟 bFeaturesReg := 0;ZNMLinux联盟 bSectorCountReg := 1;ZNMLinux联盟 bSectorNumberReg := 1;ZNMLinux联盟 bCylLowReg := 0;ZNMLinux联盟 bCylHighReg := 0;ZNMLinux联盟 bDriveHeadReg := $A0;ZNMLinux联盟 bCommandReg := IDE_ID_FUNCTION;ZNMLinux联盟 end;ZNMLinux联盟 end;ZNMLinux联盟 if not DeviceIoControl( hDevice, DFP_RECEIVE_DRIVE_DATA,ZNMLinux联盟 pInData, SizeOf(TSendCmdInParams)-1, pOutData,ZNMLinux联盟 W9xBufferSize, cbBytesReturned, nil ) then Exit;ZNMLinux联盟 finallyZNMLinux联盟 CloseHandle(hDevice);ZNMLinux联盟 end;ZNMLinux联盟 end;ZNMLinux联盟 with PIdSector(PChar(pOutData)+16)^ doZNMLinux联盟 beginZNMLinux联盟 ChangeByteOrder(sSerialNumber,SizeOf(sSerialNumber));ZNMLinux联盟 SetString(Result,sSerialNumber,SizeOf(sSerialNumber));ZNMLinux联盟 end;ZNMLinux联盟 end;ZNMLinux联盟 ZNMLinux联盟 END.ZNMLinux联盟 ZNMLinux联盟 //win98要 c:windowssystem的smartvsd.vxdZNMLinux联盟 //copy to c:windowssystemiosubsysZNMLinux联盟 //reboot your computer and okZNMLinux联盟 //2000 and nt do not need |
ZNMLinux联盟 ZNMLinux联盟 得到硬盘物理序号:ZNMLinux联盟 ZNMLinux联盟
ZNMLinux联盟 uses hdid;ZNMLinux联盟 ZNMLinux联盟 hdsn:=trim(GetIdeDiskSerialNumber); |
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论 |
|
|
|
|
|