1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143:
| . . . var Form1: TForm1;
Type TIDERegs = packed record bFeaturesReg : Byte; bSectorCountReg : Byte; bSectorNumberReg : Byte; bCylLowReg : Byte; bCylHighReg : Byte; bDriveHeadReg : Byte; bCommandReg : Byte; bReserved : Byte; end; IDEREGS = TIDERegs; PIDERegs = ^TIDERegs;
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 : ULONG; wMultSectorStuff : Word; ulTotalAddressableSectors : ULONG; wSingleWordDMA : Word; wMultiWordDMA : Word; wFlowControlPIOSupported : Word; wMinimumMultiWordDMA : Word; wRecommendedMultiWordDMA : Word; wMinimumPIOCycleWOFlow : Word; wMinimumPIOCycleIORDYFlow : Word; bReserved1 : Array[0..21] of Byte; wMajorVersionNumber : Word; wMinorVersionNumber : Word; wCommandSetSupported : Word; wCommandSetSupported2 : Word; wCommandSetExtension : Word; wCommandSetFeatureEnabled1 : Word; wCommandSetFeatureEnabled2 : Word; wCommandSetFeatureEnabled3 : Word; wUltraDMAMode : Word; wTimeRequiredErase : Word; wTimeRequiredEnhancedErase : Word; wAbleMode : Word; bReserved2 : Array[0..71] of Byte; wSecurityModeFeature : Word; wCurrentFeatureOption : Word; wReserved2 : Word; wInitialPowerMode : Word; bReserved3 : Array[0..247] of Byte; end; PIdSector = ^TIdSector;
const BufferSize = SizeOf(TIDERegs)+4; IOCTL_IDE_PASS_THROUGH = $0004d028;
implementation
{$R *.dfm}
Function IdeRegPassThrough(Device: String; var ideregs: TIDERegs ): Boolean; var ret:BOOL; hDevice : THandle; cbBytesReturned : DWORD; pInData : PIDERegs; pOutData : Pointer; Buffer : Array[0..BufferSize-1] of Byte; begin Result := False; FillChar(Buffer,BufferSize,#0);
hDevice := CreateFile( PChar(Device), GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0 ); if hDevice=INVALID_HANDLE_VALUE then Exit; try pInData := @Buffer; pOutData := pInData; pInData^ := ideregs; ret := DeviceIoControl( hDevice, IOCTL_IDE_PASS_THROUGH, @Buffer, BufferSize, @Buffer, BufferSize, cbBytesReturned, nil ); if not ret then begin Exit; end; ideregs := PIDERegs(pOutData)^; finally CloseHandle(hDevice); end; Result := True; end;
function GetSerialNumber(const ADrive: Char): Integer; var SerialNum: DWORD; Dummy: DWord; Buffer: array[0..255] of Char; begin Result := 0; if GetVolumeInformation(PChar(ADrive+':\'), Buffer, SizeOf(Buffer), @SerialNum, Dummy, Dummy, nil, 0) then Result:=SerialNum else RaiseLastOSError; end;
function GetHardDiskSerial(const DriveLetter: Char): string; var NotUsed: DWORD; VolumeFlags: DWORD; VolumeInfo: array[0..MAX_PATH] of Char; VolumeSerialNumber: DWORD; begin GetVolumeInformation(PChar(DriveLetter + ':\'), nil, SizeOf(VolumeInfo), @VolumeSerialNumber, NotUsed, VolumeFlags, nil, 0); Result := Format('Label: %s,VolSer: %8.8X',[VolumeInfo, VolumeSerialNumber]) end; |