相关资料:

https://zhidao.baidu.com/question/195408580.html

注意事项:

1.记得右击以管理员运行。

2.SysUtils 在XE中要改为System.SysUtils。

实例代码:

  1 unit Unit1;
  2
  3 interface
  4
  5 uses
  6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7   Dialogs, StdCtrls, ExtCtrls, Vcl.Imaging.jpeg;
  8
  9 type
 10   TForm1 = class(TForm)
 11     Panel1: TPanel;
 12     Memo1: TMemo;
 13     Button1: TButton;
 14     Label1: TLabel;
 15     Image1: TImage;
 16     procedure Button1Click(Sender: TObject);
 17   private
 18     { Private declarations }
 19   public
 20     { Public declarations }
 21   end;
 22
 23 var
 24   Form1: TForm1;
 25
 26 implementation
 27
 28 {$R *.dfm}
 29
 30 function GetScsiSerialNumber(const i: smallint): string;
 31 type
 32   TScsiPassThrough = record
 33     Length: Word;
 34     ScsiStatus: Byte;
 35     PathId: Byte;
 36     TargetId: Byte;
 37     Lun: Byte;
 38     CdbLength: Byte;
 39     SenseInfoLength: Byte;
 40     DataIn: Byte;
 41     DataTransferLength: ULONG;
 42     TimeOutValue: ULONG;
 43     DataBufferOffset: DWORD;
 44     SenseInfoOffset: ULONG;
 45     Cdb: array[0..15] of Byte;
 46   end;
 47   TScsiPassThroughWithBuffers = record
 48     spt: TScsiPassThrough;
 49     bSenseBuf: array[0..31] of Byte;
 50     bDataBuf: array[0..191] of Byte;
 51   end;
 52 var
 53   dwReturned: DWORD;
 54   len: DWORD;
 55   Buffer: array[0..SizeOf(TScsiPassThroughWithBuffers) + SizeOf(TScsiPassThrough) - 1] of Byte;
 56   sptwb: TScsiPassThroughWithBuffers absolute Buffer;
 57   hDevice: thandle;
 58 begin
 59   Result := '';
 60   if SysUtils.win32Platform = VER_PLATFORM_WIN32_NT then
 61   begin
 62     if i = 0 then
 63       hDevice := CreateFile('//./PhysicalDrive0',
 64         GENERIC_READ or GENERIC_WRITE,
 65         FILE_SHARE_READ or FILE_SHARE_WRITE,
 66         nil, OPEN_EXISTING, 0, 0)
 67     else
 68       hDevice := CreateFile('//./PhysicalDrive1',
 69         GENERIC_READ or GENERIC_WRITE,
 70         FILE_SHARE_READ or FILE_SHARE_WRITE,
 71         nil, OPEN_EXISTING, 0, 0);
 72   end
 73   else exit;
 74   if hDevice = invalid_handle_value then exit;
 75   FillChar(Buffer, SizeOf(Buffer), #0);
 76   with sptwb.spt do
 77   begin
 78     Length := SizeOf(TScsiPassThrough);
 79     CdbLength := 6; // CDB6GENERIC_LENGTH
 80     SenseInfoLength := 24;
 81     DataIn := 1; // SCSI_IOCTL_DATA_IN
 82     DataTransferLength := 192;
 83     TimeOutValue := 2;
 84     DataBufferOffset := PChar(@sptwb.bDataBuf) - PChar(@sptwb);
 85     SenseInfoOffset := PChar(@sptwb.bSenseBuf) - PChar(@sptwb);
 86     Cdb[0] := $12; //  OperationCode := SCSIOP_INQUIRY;
 87     Cdb[1] := $01; //  Flags := CDB_INQUIRY_EVPD;  Vital product data
 88     Cdb[2] := $80; //  PageCode            Unit serial number
 89     Cdb[4] := 192; // AllocationLength
 90   end;
 91   len := sptwb.spt.DataBufferOffset + sptwb.spt.DataTransferLength;
 92   if DeviceIoControl(hDevice, $0004D004, @sptwb, SizeOf(TScsiPassThrough), @sptwb, len, dwReturned, nil)
 93     and ((PChar(@sptwb.bDataBuf) + 1)^ = #$80) then
 94     SetString(Result, PChar(@sptwb.bDataBuf) + 4, Ord((PChar(@sptwb.bDataBuf) + 3)^));
 95 end;
 96
 97 function GetIdeSerialNumber: pchar;
 98 const IDENTIFY_BUFFER_SIZE = 512;
 99 type
100   TIDERegs = packed record
101     bFeaturesReg: BYTE;
102     bSectorCountReg: BYTE;
103     bSectorNumberReg: BYTE;
104     bCylLowReg: BYTE;
105     bCylHighReg: BYTE;
106     bDriveHeadReg: BYTE;
107     bCommandReg: BYTE;
108     bReserved: BYTE;
109   end;
110   TSendCmdInParams = packed record
111     cBufferSize: DWORD;
112     irDriveRegs: TIDERegs;
113     bDriveNumber: BYTE;
114     bReserved: array[0..2] of Byte;
115     dwReserved: array[0..3] of DWORD;
116     bBuffer: array[0..0] of Byte;
117   end;
118   TIdSector = packed record
119     wGenConfig: Word;
120     wNumCyls: Word;
121     wReserved: Word;
122     wNumHeads: Word;
123     wBytesPerTrack: Word;
124     wBytesPerSector: Word;
125     wSectorsPerTrack: Word;
126     wVendorUnique: array[0..2] of Word;
127     sSerialNumber: array[0..19] of CHAR;
128     wBufferType: Word;
129     wBufferSize: Word;
130     wECCSize: Word;
131     sFirmwareRev: array[0..7] of Char;
132     sModelNumber: array[0..39] of Char;
133     wMoreVendorUnique: Word;
134     wDoubleWordIO: Word;
135     wCapabilities: Word;
136     wReserved1: Word;
137     wPIOTiming: Word;
138     wDMATiming: Word;
139     wBS: Word;
140     wNumCurrentCyls: Word;
141     wNumCurrentHeads: Word;
142     wNumCurrentSectorsPerTrack: Word;
143     ulCurrentSectorCapacity: DWORD;
144     wMultSectorStuff: Word;
145     ulTotalAddressableSectors: DWORD;
146     wSingleWordDMA: Word;
147     wMultiWordDMA: Word;
148     bReserved: array[0..127] of BYTE;
149   end;
150   PIdSector = ^TIdSector;
151   TDriverStatus = packed record
152     bDriverError: Byte;
153     bIDEStatus: Byte;
154     bReserved: array[0..1] of Byte;
155     dwReserved: array[0..1] of DWORD;
156   end;
157   TSendCmdOutParams = packed record
158     cBufferSize: DWORD;
159     DriverStatus: TDriverStatus;
160     bBuffer: array[0..0] of BYTE;
161   end;
162   procedure ChangeByteOrder(var Data; Size: Integer);
163   var
164     ptr: Pchar;
165     i: Integer;
166     c: Char;
167   begin
168     ptr := @Data;
169     for I := 0 to (Size shr 1) - 1 do begin
170       c := ptr^;
171       ptr^ := (ptr + 1)^;
172       (ptr + 1)^ := c;
173       Inc(ptr, 2);
174     end;
175   end;
176 var
177   hDevice: Thandle;
178   cbBytesReturned: DWORD;
179   SCIP: TSendCmdInParams;
180   aIdOutCmd: array[0..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE - 1) - 1] of Byte;
181   IdOutCmd: TSendCmdOutParams absolute aIdOutCmd;
182 begin
183   Result := '';
184   if SysUtils.Win32Platform = VER_PLATFORM_WIN32_NT then
185     //   Windows   NT,   Windows   2000
186     hDevice := CreateFile('//./PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,
187       FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0)
188   else
189     //   Version   Windows   95   OSR2,   Windows   98
190     hDevice := CreateFile('//./SMARTVSD', 0, 0, nil, CREATE_NEW, 0, 0);
191   if hDevice = INVALID_HANDLE_VALUE then Exit;
192   try
193     FillChar(SCIP, SizeOf(TSendCmdInParams) - 1, #0);
194     FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #0);
195     cbBytesReturned := 0;
196     with SCIP do begin
197       cBufferSize := IDENTIFY_BUFFER_SIZE;
198       with irDriveRegs do begin
199         bSectorCountReg := 1;
200         bSectorNumberReg := 1;
201         bDriveHeadReg := $A0;
202         bCommandReg := $EC;
203       end;
204     end;
205     if not DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - 1,
206       @aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil) then Exit;
207   finally
208     CloseHandle(hDevice);
209   end;
210   with PIdSector(@IdOutCmd.bBuffer)^ do begin
211     ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber));
212     (Pchar(@sSerialNumber) + SizeOf(sSerialNumber))^ := #0;
213     Result := Pchar(@sSerialNumber);
214   end;
215 end;
216
217 procedure TForm1.Button1Click(Sender: TObject);
218 var
219   stmp:String;
220 begin
221   //记得右击以管理员运行
222   stmp := StrPas(PAnsiChar(GetIdeSerialNumber));
223   if stmp<>'' then
224   begin
225     Memo1.Lines.Add('无参:' + stmp);
226   end
227   else
228   begin
229     stmp := Trim(GetScsiSerialNumber(0));
230     Memo1.Lines.Add('有参:' + stmp);
231   end;
232 end;
233
234 end.

View Code

获得硬盘的ID序列号(XE10.1+WIN8.1)相关推荐

  1. 纯VB代码取得硬盘的物理序列号

    纯VB代码取得硬盘的物理序列号     网上有很多获取硬盘序列号的代码,但大部分都只能取得逻辑分区的序列号,而不能取得硬盘的物理序列号.我们知道,逻辑分区的序列号是FORMAT时产生的,重新FORMA ...

  2. java+redis+lua生成自动增长的ID序列号

    1.编写lua脚本用于生成主键ID序列号,内容如下 local key = tostring(KEYS[1]); local count = tonumber(KEYS[2]); local date ...

  3. 透过BIOS的ID序列号查询主板厂商

    我听说根据开机后屏幕上显示的BIOS 的ID 序列号可以识别主板生产厂商的信息,我的主板采用的是Award的BIOS,可我找到后仍然不知道这块板子的生产厂商,您能不能将该编号所对应的厂商名称挑主要的介 ...

  4. [转]获取机器的硬件信息(CPU ID序列号, 主板信息,硬盘序列号,系统信息)

    本文转自:http://www.msproject.cn/Article/GetHardwareInformation.aspx 原文如下: -------- 在很多情况下,你可能都需要得到微机的硬件 ...

  5. 修改固态硬盘的物理序列号_买固态怕踩坑?收下这些软件,轻松鉴别好坏

    再有半个月,就迎接年中的促销旺季.不少朋友都希望趁着各种优惠.跳楼价,组一台梦想机.升级一下自己的电脑.说到体验升级,相信就算是DIY新手和硬件小白都知道,要想电脑快,必须选固态. 但是固态参数多,又 ...

  6. python获取机器唯一标识_通过python 获取cpu和硬盘等硬件序列号组成的唯一识别码...

    import wmi c = wmi.WMI() def yingpan(): # # 硬盘序列号 cc = "" for physical_disk in c.Win32_Dis ...

  7. 获取电脑cpu,硬盘,网卡序列号

    1.命令行获取 cpu序列号:wmic cpu get processorid 硬盘序列号: 1)diskpart 2)list disk 3)select disk 0 4)detail disk ...

  8. Linux双系统硬盘识别不了,Linux和win8双系统磁盘错误问题

    我之前是win7+ubuntu的双系统,ubuntu下读写win7硬盘没有任何问题,但是升级win8之后发现一个问题,在ubuntu下不能挂载windows系统盘了,更严重的是在ubuntu下写入wi ...

  9. 获取STM32的唯一ID序列号(可用于加密)

    1.基本描述 在STM32的全系列MCU中均有一个96位的唯一设备标识符.在ST的相关资料中,对其功能的描述有3各方面: 用作序列号(例如 USB 字符串序列号或其它终端应用程序) 在对内部 Flas ...

  10. 怎么查看计算机当前用户和组,如何查看电脑硬盘的ID号与详细信息-电脑自学网...

    用户们在使用电脑系统时,电脑系统都会有对应的ID号与详细信息,如果用户在需要登记win7系统用户电脑的硬盘ID时,却发现不知道应该如何查看,那么应该如何查看呢? 操作步骤: 1.首先点击电脑左下角的& ...

最新文章

  1. java 中的finally你知多少_Java 处理异常 9 个最佳实践,你知道几个?
  2. oracle sum 数据类型,五、Oracle内置函数
  3. python 的进程池不可嵌套
  4. 2021春季每日一题【week5 未完结】
  5. 写jQuery插件该注意的
  6. Luogu 1941 飞扬的小鸟
  7. linux 测试程序性能,推荐一款Linux系统的性能测试软件
  8. leetcode409. 最长回文串
  9. java opencv bytearray转mat_如何用Python+OpenCV处理图像色彩?终于有人讲明白了
  10. 集群提交HBase代码报错:Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguratio
  11. Android fastboot下载模式或reboot流程解析
  12. Intellij IDEA创建Scala项目
  13. VRCORE开发者大赛圆满落幕,中国虚拟现实内容大集结
  14. 科普|2022数字调度机进网认证测试项,CTA认证、入网认证、调度机
  15. 【二 HLS】HLS接口的简单介绍
  16. 清除所有浏览器历史数据脚本_不要让浏览器吸收所有数据
  17. 怎么维护linux环境,Linux系统是如何维护时间的
  18. poj 1837 Balance
  19. Mysql基础入门篇(二)
  20. Java的switch选择结构

热门文章

  1. 2016年9月ccf
  2. 闽江学院2015-2016学年下学期《软件测试》课程-第六次博客作业
  3. BZOJ_1003_[ZJOI2006]_物流运输_(动态规划+最短路)
  4. Python部分输出
  5. SET NOCOUNT
  6. Double binary trees
  7. vue开发中v-for在Eslint的规则检查下出现:Elements in iteration expect to have 'v-bind:key' directives...
  8. C#应用视频教程3.4 Halcon+C#测试
  9. python 装饰器,登录小练习
  10. 【JZOJ4922】【NOIP2017提高组模拟12.17】环