
Опытный
 
Профиль
Группа: Участник
Сообщений: 332
Регистрация: 27.12.2008
Репутация: 1 Всего: 1
|
еще что то не то! (речь о Delphi2009), вот так работает:Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
const SMART_GET_VERSION = $074080; SMART_SEND_DRIVE_COMMAND = $07C084; SMART_RCV_DRIVE_DATA = $07C088;
// Values of ds_bDriverError DRVERR_NO_ERROR = 0; DRVERR_IDE_ERROR = 1; DRVERR_INVALID_FLAG = 2; DRVERR_INVALID_COMMAND = 3; DRVERR_INVALID_BUFFER = 4; DRVERR_INVALID_DRIVE = 5; DRVERR_INVALID_IOCTL = 6; DRVERR_ERROR_NO_MEM = 7; DRVERR_INVALID_REGISTER = 8; DRVERR_NOT_SUPPORTED = 9; DRVERR_NO_IDE_DEVICE = 10;
// Values of ir_bCommandReg ATAPI_ID_CMD = $A1; ID_CMD = $EC; SMART_CMD = $B0;
type TIdeRegs = packed record bFeaturesReg, bSectorCountReg, bSectorNumberReg, bCylLowReg, bCylHighReg, bDriveHeadReg, bCommandReg, bReserved: Byte; end;
TDriverStatus = packed record bDriverError: Byte; bIDEError: Byte; bReserved: array[1..2] of Byte; dwReserved: array[1..2] of DWORD; end;
TSendCmdInParams = packed record dwBufferSize: DWORD; irDriveRegs: TIdeRegs; bDriveNumber: Byte; bReserved: array[1..3] of Byte; dwReserved: array[1..4] of DWORD; bBuffer: Byte; end;
TSendCmdOutParams = packed record dwBufferSize: DWORD; dsDriverStatus: TDriverStatus; bBuffer: array[1..512] of Byte; end;
TGetVersionInParams = packed record bVersion, bRevision, bReserved, bIDEDeviceMap: Byte; dwCapabilities: DWORD; dwReserved: array[1..4] of DWORD; end;
procedure CorrectDevInfo(var _params: TSendCmdOutParams); asm lea edi, _params.bBuffer add edi,14h mov ecx,0Ah @@SerNumLoop: mov ax,[edi] xchg al,ah stosw loop @@SerNumLoop add edi,6 mov cl,18h @@ModelNumLoop: mov ax,[edi] xchg al,ah stosw loop @@ModelNumLoop end;
procedure TForm1.Button1Click(Sender: TObject); var i: DWORD; tmp: Ansistring; dev: THandle; scip: TSendCmdInParams; scop: TSendCmdOutParams; gvip: TGetVersionInParams; ret: DWORD; begin dev := CreateFile('\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if dev <> INVALID_HANDLE_VALUE then begin if DeviceIoControl(dev, SMART_GET_VERSION, nil, 0, @gvip, SizeOf(gvip), ret, nil) then begin scip.dwBufferSize := 512; scip.bDriveNumber := 0; scip.irDriveRegs.bSectorCountReg := 1; scip.irDriveRegs.bSectorNumberReg := 1; scip.irDriveRegs.bDriveHeadReg := $A0; // ??? scip.irDriveRegs.bCommandReg := ID_CMD; // ???
if not DeviceIoControl(dev, SMART_RCV_DRIVE_DATA, @scip, SizeOf(scip), @scop, SizeOf(scop), ret, nil) then ShowMessage(SysErrorMessage(GetLastError)) else if scop.dsDriverStatus.bDriverError = DRVERR_NO_ERROR then begin CorrectDevInfo(scop); SetLength(tmp, 20); Move(scop.bBuffer[21], tmp[1], 20); ShowMessage(' Serial Number: ' + tmp);
SetLength(tmp, 8); Move(scop.bBuffer[47], tmp[1], 8); ShowMessage('Firmware Revision: ' + tmp); SetLength(tmp, 40); Move(scop.bBuffer[55], tmp[1], 40); ShowMessage(' Model: ' + tmp); end else ShowMessageFmt('Error code: %d', [scop.dsDriverStatus.bDriverError]) end else ShowMessage(SysErrorMessage(GetLastError)); CloseHandle(dev); end; end;
end.
|
а так не работаетКод | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons;
type TForm1 = class(TForm) BitBtn1: TBitBtn; procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } function HddSerialAndModel(const Param:String):AnsiString; end;
var Form1: TForm1;
implementation
{$R *.dfm}
const SMART_GET_VERSION = $074080; SMART_SEND_DRIVE_COMMAND = $07C084; SMART_RCV_DRIVE_DATA = $07C088; // Values of ds_bDriverError DRVERR_NO_ERROR = 0; DRVERR_IDE_ERROR = 1; DRVERR_INVALID_FLAG = 2; DRVERR_INVALID_COMMAND = 3; DRVERR_INVALID_BUFFER = 4; DRVERR_INVALID_DRIVE = 5; DRVERR_INVALID_IOCTL = 6; DRVERR_ERROR_NO_MEM = 7; DRVERR_INVALID_REGISTER = 8; DRVERR_NOT_SUPPORTED = 9; DRVERR_NO_IDE_DEVICE = 10; // Values of ir_bCommandReg ATAPI_ID_CMD = $A1; ID_CMD = $EC; SMART_CMD = $B0;
type TIdeRegs = packed record bFeaturesReg, bSectorCountReg, bSectorNumberReg, bCylLowReg, bCylHighReg, bDriveHeadReg, bCommandReg, bReserved: Byte; end;
TDriverStatus = packed record bDriverError: Byte; bIDEError: Byte; bReserved: array[1..2] of Byte; dwReserved: array[1..2] of DWORD; end;
TSendCmdInParams = packed record dwBufferSize: DWORD; irDriveRegs: TIdeRegs; bDriveNumber: Byte; bReserved: array[1..3] of Byte; dwReserved: array[1..4] of DWORD; bBuffer: Byte; end;
TSendCmdOutParams = packed record dwBufferSize: DWORD; dsDriverStatus: TDriverStatus; bBuffer: array[1..512] of Byte; end;
TGetVersionInParams = packed record bVersion, bRevision, bReserved, bIDEDeviceMap: Byte; dwCapabilities: DWORD; dwReserved: array[1..4] of DWORD; end;
procedure CorrectDevInfo(var _params: TSendCmdOutParams); asm lea edi, _params.bBuffer add edi,14h mov ecx,0Ah @@SerNumLoop: mov ax,[edi] xchg al,ah stosw loop @@SerNumLoop add edi,6 mov cl,18h @@ModelNumLoop: mov ax,[edi] xchg al,ah stosw loop @@ModelNumLoop end;
function TForm1.HddSerialAndModel(const Param:String):AnsiString; var i: DWORD; tmp: Ansistring; dev: THandle; scip: TSendCmdInParams; scop: TSendCmdOutParams; gvip: TGetVersionInParams; ret: DWORD; begin dev := CreateFile('\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if dev <> INVALID_HANDLE_VALUE then begin if DeviceIoControl(dev, SMART_GET_VERSION, nil, 0, @gvip, SizeOf(gvip), ret, nil) then begin scip.dwBufferSize := 512; scip.bDriveNumber := 0; scip.irDriveRegs.bSectorCountReg := 1; scip.irDriveRegs.bSectorNumberReg := 1; scip.irDriveRegs.bDriveHeadReg := $A0; // ??? scip.irDriveRegs.bCommandReg := ID_CMD; // ??? if not DeviceIoControl(dev, SMART_RCV_DRIVE_DATA, @scip, SizeOf(scip),@scop, SizeOf(scop), ret, nil) then ShowMessage(SysErrorMessage(GetLastError)) else if scop.dsDriverStatus.bDriverError = DRVERR_NO_ERROR then begin CorrectDevInfo(scop); if param='Serial' then begin SetLength(tmp, 20); Move(scop.bBuffer[21], tmp[1], 20); Result:=(tmp); end else if Param='Model' then begin SetLength(tmp, 40); Move(scop.bBuffer[55], tmp[1], 40); Result:=tmp; end else if Param='Firmware' then begin SetLength(tmp, 8); Move(scop.bBuffer[47], tmp[1], 8); Result:=tmp; end; end; end else ShowMessageFmt('Error code: %d', [scop.dsDriverStatus.bDriverError]) end else ShowMessage(SysErrorMessage(GetLastError)); CloseHandle(dev); end;
procedure TForm1.BitBtn1Click(Sender: TObject); begin ShowMessage(HddSerialAndModel('Serial')); end; end.
|
Чё за хрень?
|