如何得出硬盘的物理大小及硬盘出厂序列号(100分)

  • 主题发起人 主题发起人 Zythum
  • 开始时间 开始时间
用disksize函数可获得驱动器的大小.<br>function DiskSize(Drive: Byte): Int64;<br>DiskSize returns the size in bytes of the specified drive,<br>&nbsp;where 0 = Current, 1 = A, 2 = B, etc.
 
我有一个与硬件相关的控件,能够获得硬件的基本信息,更重要的是有源码的哦,要不要?
 
这里有<br>http://delphi.antdown.com/folder.asp?id=28&amp;Folder_name=各类源码
 
这里看一看<br>http://delphibbs.com/delphibbs/dispq.asp?lid=1648
 
读硬盘序列号<br>procedure TForm1.Button1Click(Sender: TObject); &nbsp;<br>var SerialNum : pdword; a, b : dword; Buffer : array [0..255] of char; &nbsp;<br>begin &nbsp;<br>&nbsp; if GetVolumeInformation('c:/', Buffer, SizeOf(Buffer), SerialNum, a, b, nil, 0) then Label1.Caption := IntToStr(SerialNum^); <br><br>end; <br><br>
 
人家是要硬盘的物理系列号呀,我知道的也就这样了。
 
这个问题已经讨论了N遍了,请用"序列号"作为关键字查询一下吧!
 
虽然讨论很多遍但一直没有完美解决方案!要么得到逻辑序列号毫无意义,要么要带个DLL<br>很不爽。
 
这里有一份本人上传的源程序,也就是“要么要带个DLL很不爽。”的程序。<br>但有全部的源代码,包括DLL,只是本人已没有心思花时间将其全部改写为*.Pas文件。<br>如果哪位有兴趣,不防写写。<br><br>http://delphi.antdown.com/dispdoc.asp?id=80
 
为何您的程序在我的带钻石硬盘的机上运行一切正常,无任何错误信息。但就是不返回硬盘<br>序号:My Hd s/n:='';
 
unit main;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<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. &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; <br>&nbsp; &nbsp; irDriveRegs &nbsp;: TIDERegs; <br>&nbsp; &nbsp; bDriveNumber : Byte; <br>&nbsp; &nbsp; bReserved &nbsp; &nbsp;: Array[0..2] of Byte; <br>&nbsp; &nbsp; dwReserved &nbsp; : Array[0..3] of DWORD;<br>&nbsp; &nbsp; bBuffer &nbsp; &nbsp; &nbsp;: Array[0..0] of Byte;<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>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br>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>function GetIdeDiskSerialNumber : String;<br><br>var <br>&nbsp; hDevice : THandle; <br>&nbsp; cbBytesReturned : DWORD; <br>&nbsp; pInData : PSendCmdInParams; <br>&nbsp; pOutData : Pointer; // PSendCmdOutParams <br>&nbsp; Buffer : Array[0..BufferSize-1] of Byte;<br>&nbsp; srbControl : TSrbIoControl absolute Buffer;<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:',<br>&nbsp; &nbsp; &nbsp; &nbsp; GENERIC_READ or GENERIC_WRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; FILE_SHARE_READ or FILE_SHARE_WRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; 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)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+SizeOf(SRB_IO_CONTROL));<br>&nbsp; &nbsp; &nbsp; &nbsp; 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,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Buffer, BufferSize, @Buffer, BufferSize,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 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,<br>&nbsp; &nbsp; &nbsp; &nbsp; CREATE_NEW, 0, 0 );<br>&nbsp; &nbsp; &nbsp; if hDevice=INVALID_HANDLE_VALUE then Exit;<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; pInData := PSendCmdInParams(@Buffer);<br>&nbsp; &nbsp; &nbsp; &nbsp; pOutData := @pInData^.bBuffer;<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, DFP_RECEIVE_DRIVE_DATA,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pInData, SizeOf(TSendCmdInParams)-1, pOutData,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; W9xBufferSize, 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; &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>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>EDIT1.TEXT:=TRIM(GetIdeDiskSerialNumber);<br>end;<br><br>END.<br><br>//win98要 c:/windows/system/的smartvsd.vxd<br>//copy to c:/windows/system/iosubsys<br>//reboot your computer and ok<br>//2000 and nt do not need
 
接受答案了.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部