急,急,急,(200分)

  • 主题发起人 主题发起人 candylyg
  • 开始时间 开始时间
C

candylyg

Unregistered / Unconfirmed
GUEST, unregistred user!
求够一读取硬盘物理序列号和CPU ID号的delphi代码,<br>candylyg@sina.com<br>ICQ:37434800
 
&nbsp;TCPUIDARRAY=array[1..4] of Longint;<br>function GetCPUID : TCPUIDARRAY; assembler;register;<br>asm<br>&nbsp; PUSH &nbsp; &nbsp;EBX &nbsp; &nbsp; &nbsp; &nbsp; {Save affected register}<br>&nbsp; PUSH &nbsp; &nbsp;EDI<br>&nbsp; MOV &nbsp; &nbsp; EDI,EAX &nbsp; &nbsp; {@Resukt}<br>&nbsp; MOV &nbsp; &nbsp; EAX,1<br>&nbsp; DW &nbsp; &nbsp; &nbsp;$A20F &nbsp; &nbsp; &nbsp; {CPUID Command}<br>&nbsp; STOSD {CPUID[1]}<br>&nbsp; MOV &nbsp; &nbsp; EAX,EBX<br>&nbsp; STOSD &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {CPUID[2]}<br>&nbsp; MOV &nbsp; &nbsp; EAX,ECX<br>&nbsp; STOSD &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {CPUID[3]}<br>&nbsp; MOV &nbsp; &nbsp; EAX,EDX<br>&nbsp; STOSD &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {CPUID[4]}<br>&nbsp; POP &nbsp; &nbsp; EDI {Restore registers}<br>&nbsp; POP &nbsp; &nbsp; EBX<br>end;<br><br>function GetCPUIDStr:String;<br>var<br>&nbsp; CPUID:TCPUIDARRAY;<br>begin<br>&nbsp; CPUID:=GetCPUID;<br>&nbsp; Result:=IntToHex(CPUID[1],4)+IntToHex(CPUID[2],4)+IntToHex(CPUID[3],4)+IntToHex(CPUID[4],4);<br>end;<br>给100分吧
 
获取磁盘序列号 &nbsp;<br>摘 要:不是取得卷标号,而是物理ID号<br>关键字:磁盘序列号<br>类 别:系统控制<br>&nbsp;<br>&nbsp;<br>type<br>&nbsp; MIDPtr = ^MIDRec;<br>&nbsp; MIDRec = Record<br>&nbsp; &nbsp; InfoLevel: word;<br>&nbsp; &nbsp; SerialNum: LongInt;<br>&nbsp; &nbsp; VolLabel: Packed Array [0..10] of Char;<br>&nbsp; &nbsp; FileSysType: Packed Array [0..7] of Char;<br>&nbsp; end;<br><br>function GetDriveSerialNum(MID: MIDPtr; drive: Word): Boolean; assembler;<br>asm<br>&nbsp; push &nbsp;DS &nbsp; &nbsp;{ Just for safety, I dont think its really needed }<br>&nbsp; mov &nbsp; ax,440Dh { Function Get Media ID }<br>&nbsp; mov &nbsp; bx,drive &nbsp; &nbsp;{ drive no (0-Default, 1-A ...) }<br>&nbsp; mov &nbsp; cx,0866h &nbsp;{ category and minor code }<br>&nbsp; lds &nbsp; dx,MID &nbsp; &nbsp; &nbsp;{ Load pointeraddr. }<br>&nbsp; call &nbsp;DOS3Call &nbsp; { Supposed to be faster than INT 21H }<br>&nbsp; jc &nbsp; &nbsp;@@err<br>&nbsp; mov &nbsp; al,1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { No carry so return TRUE }<br>&nbsp; jmp &nbsp; @@ok<br>&nbsp;@@err:<br>&nbsp; mov &nbsp; al,0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { Carry set so return FALSE }<br>&nbsp;@@ok:<br>&nbsp; pop &nbsp; DS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ Restore DS, were not supposed to change it }<br>end;<br><br>procedure TForm1.NrBtnClick(Sender: TObject);<br>var<br>&nbsp; Info: MIDRec;<br>begin<br>&nbsp; Info.InfoLevel:=0; { Information Level }<br>&nbsp; If GetDriveSerialNum(@Info,0) then &nbsp;{ Do something with it... }<br>&nbsp; &nbsp; ListBox.Items.Add(IntToStr(Info.SerialNum)+' '+Info.VolLabel);<br>end;<br><br><br><br>--------------------------------------------------------------------------------<br>BOOL GetVolumeInformation(<br><br>&nbsp; &nbsp; LPCTSTR lpRootPathName, // address of root directory of the file system<br>&nbsp; &nbsp; LPTSTR lpVolumeNameBuffer, // address of name of the volume<br>&nbsp; &nbsp; DWORD nVolumeNameSize, // length of lpVolumeNameBuffer<br>&nbsp; &nbsp; LPDWORD lpVolumeSerialNumber, // address of volume serial number<br>&nbsp; &nbsp; LPDWORD lpMaximumComponentLength, // address of system's maximum filename length<br>&nbsp; &nbsp; LPDWORD lpFileSystemFlags, // address of file system flags<br>&nbsp; &nbsp; LPTSTR lpFileSystemNameBuffer, // address of name of file system<br>&nbsp; &nbsp; DWORD nFileSystemNameSize &nbsp;// length of lpFileSystemNameBuffer<br>&nbsp; &nbsp;);<br><br><br><br>--------------------------------------------------------------------------------<br>获取SCSI硬盘序列号<br><br>问题提出/摘要:<br><br>对于IDE硬盘,你可以使用S.M.A.R.T. API的函数来获取序列号。但对SCSI硬盘,它无法工作。但我们可以使用DeviceIoControl来获取DeviceIoControl设备序列号.<br><br>&nbsp;<br><br>&nbsp;<br><br>回答:<br><br>&nbsp; 下面是代码:<br><br>&nbsp; program ScsiSN;<br><br>&nbsp;<br><br>&nbsp; // 目的:简单的控制台程序来显示SCSI硬盘的序列号<br><br>&nbsp;<br><br>&nbsp; {$APPTYPE CONSOLE}<br><br>&nbsp;<br><br>&nbsp; uses<br><br>&nbsp; Windows, SysUtils;<br><br>&nbsp;<br><br>&nbsp; //-------------------------------------------------------------<br><br>&nbsp; function GetDeviceHandle( sDeviceName : String ) : THandle;<br><br>&nbsp; begin<br><br>&nbsp; Result := CreateFile( PChar('//./'+sDeviceName),<br><br>&nbsp; GENERIC_READ or GENERIC_WRITE,<br><br>&nbsp; FILE_SHARE_READ or FILE_SHARE_WRITE,<br><br>&nbsp; nil, OPEN_EXISTING, 0, 0 )<br><br>&nbsp; end;<br><br>&nbsp;<br><br>&nbsp; //-------------------------------------------------------------<br><br>&nbsp; function ScsiHddSerialNumber( DeviceHandle : THandle ) : String;<br><br>&nbsp; {$ALIGN ON}<br><br>&nbsp; type<br><br>&nbsp; TScsiPassThrough = record<br><br>&nbsp; Length : Word;<br><br>&nbsp; ScsiStatus : Byte;<br><br>&nbsp; PathId : Byte;<br><br>&nbsp; TargetId : Byte;<br><br>&nbsp; Lun : Byte;<br><br>&nbsp; CdbLength : Byte;<br><br>&nbsp; SenseInfoLength : Byte;<br><br>&nbsp; DataIn : Byte;<br><br>&nbsp; DataTransferLength : ULONG;<br><br>&nbsp; TimeOutValue : ULONG;<br><br>&nbsp; DataBufferOffset : DWORD;<br><br>&nbsp; SenseInfoOffset : ULONG;<br><br>&nbsp; Cdb : Array[0..15] of Byte;<br><br>&nbsp; end;<br><br>&nbsp; TScsiPassThroughWithBuffers = record<br><br>&nbsp; spt : TScsiPassThrough;<br><br>&nbsp; bSenseBuf : Array[0..31] of Byte;<br><br>&nbsp; bDataBuf : Array[0..191] of Byte;<br><br>&nbsp; end;<br><br>&nbsp; {ALIGN OFF}<br><br>&nbsp; var dwReturned : DWORD;<br><br>&nbsp; len : DWORD;<br><br>&nbsp; Buffer : Array[0..255] of Byte;<br><br>&nbsp; sptwb : TScsiPassThroughWithBuffers absolute Buffer;<br><br>&nbsp; begin<br><br>&nbsp; Result := '';<br><br>&nbsp; FillChar(Buffer,SizeOf(Buffer),#0);<br><br>&nbsp; with sptwb.spt do<br><br>&nbsp; begin<br><br>&nbsp; Length := SizeOf(TScsiPassThrough);<br><br>&nbsp; CdbLength := 6; // CDB6GENERIC_LENGTH<br><br>&nbsp; SenseInfoLength := 24;<br><br>&nbsp; DataIn := 1; // SCSI_IOCTL_DATA_IN<br><br>&nbsp; DataTransferLength := 192;<br><br>&nbsp; TimeOutValue := 2;<br><br>&nbsp; DataBufferOffset := PChar(@sptwb.bDataBuf)-PChar(@sptwb);<br><br>&nbsp; SenseInfoOffset := PChar(@sptwb.bSenseBuf)-PChar(@sptwb);<br><br>&nbsp; Cdb[0] := $12; // OperationCode := SCSIOP_INQUIRY;<br><br>&nbsp; Cdb[1] := $01; // Flags := CDB_INQUIRY_EVPD; Vital product data<br><br>&nbsp; Cdb[2] := $80; // PageCode Unit serial number<br><br>&nbsp; Cdb[4] := 192; // AllocationLength<br><br>&nbsp; end;<br><br>&nbsp; len := sptwb.spt.DataBufferOffset+sptwb.spt.DataTransferLength;<br><br>&nbsp; if DeviceIoControl( DeviceHandle, $0004d004, @sptwb, SizeOf(TScsiPassThrough), @sptwb, len, dwReturned, nil )<br><br>&nbsp; and ((PChar(@sptwb.bDataBuf)+1)^=#$80)<br><br>&nbsp; then<br><br>&nbsp; SetString( Result, PChar(@sptwb.bDataBuf)+4,<br><br>&nbsp; Ord((PChar(@sptwb.bDataBuf)+3)^) );<br><br>&nbsp; end;<br><br>&nbsp;<br><br>&nbsp;<br><br>&nbsp; //=============================================================<br><br>&nbsp; var<br><br>&nbsp; hDevice : THandle = 0;<br><br>&nbsp; sSerNum, sDeviceName : String;<br><br>&nbsp;<br><br>&nbsp; begin<br><br>&nbsp; sDeviceName := ParamStr(1);<br><br>&nbsp; if sDeviceName='' then<br><br>&nbsp; begin<br><br>&nbsp; WriteLn;<br><br>&nbsp; WriteLn('Display SCSI-2 device serial number.');<br><br>&nbsp; WriteLn;<br><br>&nbsp; WriteLn('Using:');<br><br>&nbsp; WriteLn;<br><br>&nbsp; if Win32Platform=VER_PLATFORM_WIN32_NT then // Windows NT/2000<br><br>&nbsp; WriteLn(' ScsiSN PhysicalDrive0')<br><br>&nbsp; else<br><br>&nbsp; WriteLn(' ScsiSN C:');<br><br>&nbsp; WriteLn(' ScsiSN Cdrom0');<br><br>&nbsp; WriteLn(' ScsiSN Tape0');<br><br>&nbsp; WriteLn;<br><br>&nbsp; Exit;<br><br>&nbsp; end;<br><br>&nbsp; hDevice := GetDeviceHandle(sDeviceName);<br><br>&nbsp; if hDevice=INVALID_HANDLE_VALUE then<br><br>&nbsp; WriteLn('Error on GetDeviceHandle: ',SysErrorMessage(GetLastError))<br><br>&nbsp; else<br><br>&nbsp; try<br><br>&nbsp; sSerNum := ScsiHddSerialNumber(hDevice);<br><br>&nbsp; if sSerNum='' then<br><br>&nbsp; WriteLn('Error on DeviceIoControl: ',<br><br>&nbsp; SysErrorMessageGetLastError))<br><br>&nbsp; else<br><br>&nbsp; WriteLn('Device '+sDeviceName<br><br>&nbsp; +' serial number = "',sSerNum,'"');<br><br>&nbsp; finally<br><br>&nbsp; CloseHandle(hDevice);<br><br>&nbsp; end;<br><br>&nbsp; end.<br><br>&nbsp;<br><br>&nbsp; // 以下站点可获取更多关于SCSI命令的信息:<br><br>&nbsp; // ftp://ftp.t10.org/t10/drafts/scsi-1/<br><br>&nbsp;<br><br>&nbsp; // ftp://ftp.t10.org/t10/drafts/spc/<br><br>&nbsp;<br><br>&nbsp; // ftp://ftp.t10.org/t10/drafts/spc2/ <br><br><br><br>
 
to driver<br>Undeclared inentifier' TCPUIDARRAY'
 
你得将这一句写在上面:<br>type<br>&nbsp; TCPUIDARRAY=array[1..4] of Longint;<br>
 
我希望能支持所有WIN32平台,并支持maxtor,seagate,IBM,quantun,scsi,等绝大部分主流硬盘.<br>谢谢.
 
to driver<br>还是不行,你写个最简单的例程吧.
 
怎么能不行呢?那儿不行啊?<br>类型的声明放在TForm1=TForm上面<br>procedure TForm1.Button1Click(Sender:TObject)<br>begin<br>&nbsp; edit1.text:=GetCPUIDStr;<br>end;
 
to 原野飞俠<br>operand size mismatch (lds dx,MID0<br>undeclared identifier'dos3call'
 
to driver<br>得到的是不可修改的物理序列号吗?<br>支持各厂商及各型号的CPU吗?
 
to原野飞俠<br>老兄,为什么会出错呢?缺少一个函数.
 
我有cpuID和IDE serial读取的缘代码,<br>在D5,6,7下测试通过.<br>QQ:37434800
 
接受答案了.
 
后退
顶部