DelphiXE公开课群:100162924、58593121 朱建强QQ:513187410

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

相关资料:

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

注意事项:

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

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

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Vcl.Imaging.jpeg; type
TForm1 = class(TForm)
Panel1: TPanel;
Memo1: TMemo;
Button1: TButton;
Label1: TLabel;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} function GetScsiSerialNumber(const i: smallint): string;
type
TScsiPassThrough = record
Length: Word;
ScsiStatus: Byte;
PathId: Byte;
TargetId: Byte;
Lun: Byte;
CdbLength: Byte;
SenseInfoLength: Byte;
DataIn: Byte;
DataTransferLength: ULONG;
TimeOutValue: ULONG;
DataBufferOffset: DWORD;
SenseInfoOffset: ULONG;
Cdb: array[..] of Byte;
end;
TScsiPassThroughWithBuffers = record
spt: TScsiPassThrough;
bSenseBuf: array[..] of Byte;
bDataBuf: array[..] of Byte;
end;
var
dwReturned: DWORD;
len: DWORD;
Buffer: array[..SizeOf(TScsiPassThroughWithBuffers) + SizeOf(TScsiPassThrough) - ] of Byte;
sptwb: TScsiPassThroughWithBuffers absolute Buffer;
hDevice: thandle;
begin
Result := '';
if SysUtils.win32Platform = VER_PLATFORM_WIN32_NT then
begin
if i = then
hDevice := CreateFile('//./PhysicalDrive0',
GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, , )
else
hDevice := CreateFile('//./PhysicalDrive1',
GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, , );
end
else exit;
if hDevice = invalid_handle_value then exit;
FillChar(Buffer, SizeOf(Buffer), #);
with sptwb.spt do
begin
Length := SizeOf(TScsiPassThrough);
CdbLength := ; // CDB6GENERIC_LENGTH
SenseInfoLength := ;
DataIn := ; // SCSI_IOCTL_DATA_IN
DataTransferLength := ;
TimeOutValue := ;
DataBufferOffset := PChar(@sptwb.bDataBuf) - PChar(@sptwb);
SenseInfoOffset := PChar(@sptwb.bSenseBuf) - PChar(@sptwb);
Cdb[] := $; // OperationCode := SCSIOP_INQUIRY;
Cdb[] := $; // Flags := CDB_INQUIRY_EVPD; Vital product data
Cdb[] := $; // PageCode Unit serial number
Cdb[] := ; // AllocationLength
end;
len := sptwb.spt.DataBufferOffset + sptwb.spt.DataTransferLength;
if DeviceIoControl(hDevice, $0004D004, @sptwb, SizeOf(TScsiPassThrough), @sptwb, len, dwReturned, nil)
and ((PChar(@sptwb.bDataBuf) + )^ = #$) then
SetString(Result, PChar(@sptwb.bDataBuf) + , Ord((PChar(@sptwb.bDataBuf) + )^));
end; function GetIdeSerialNumber: pchar;
const IDENTIFY_BUFFER_SIZE = ;
type
TIDERegs = packed record
bFeaturesReg: BYTE;
bSectorCountReg: BYTE;
bSectorNumberReg: BYTE;
bCylLowReg: BYTE;
bCylHighReg: BYTE;
bDriveHeadReg: BYTE;
bCommandReg: BYTE;
bReserved: BYTE;
end;
TSendCmdInParams = packed record
cBufferSize: DWORD;
irDriveRegs: TIDERegs;
bDriveNumber: BYTE;
bReserved: array[..] of Byte;
dwReserved: array[..] of DWORD;
bBuffer: array[..] of Byte;
end;
TIdSector = packed record
wGenConfig: Word;
wNumCyls: Word;
wReserved: Word;
wNumHeads: Word;
wBytesPerTrack: Word;
wBytesPerSector: Word;
wSectorsPerTrack: Word;
wVendorUnique: array[..] of Word;
sSerialNumber: array[..] of CHAR;
wBufferType: Word;
wBufferSize: Word;
wECCSize: Word;
sFirmwareRev: array[..] of Char;
sModelNumber: array[..] of Char;
wMoreVendorUnique: Word;
wDoubleWordIO: Word;
wCapabilities: Word;
wReserved1: Word;
wPIOTiming: Word;
wDMATiming: Word;
wBS: Word;
wNumCurrentCyls: Word;
wNumCurrentHeads: Word;
wNumCurrentSectorsPerTrack: Word;
ulCurrentSectorCapacity: DWORD;
wMultSectorStuff: Word;
ulTotalAddressableSectors: DWORD;
wSingleWordDMA: Word;
wMultiWordDMA: Word;
bReserved: array[..] of BYTE;
end;
PIdSector = ^TIdSector;
TDriverStatus = packed record
bDriverError: Byte;
bIDEStatus: Byte;
bReserved: array[..] of Byte;
dwReserved: array[..] of DWORD;
end;
TSendCmdOutParams = packed record
cBufferSize: DWORD;
DriverStatus: TDriverStatus;
bBuffer: array[..] of BYTE;
end;
procedure ChangeByteOrder(var Data; Size: Integer);
var
ptr: Pchar;
i: Integer;
c: Char;
begin
ptr := @Data;
for I := to (Size shr ) - do begin
c := ptr^;
ptr^ := (ptr + )^;
(ptr + )^ := c;
Inc(ptr, );
end;
end;
var
hDevice: Thandle;
cbBytesReturned: DWORD;
SCIP: TSendCmdInParams;
aIdOutCmd: array[..(SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE - ) - ] of Byte;
IdOutCmd: TSendCmdOutParams absolute aIdOutCmd;
begin
Result := '';
if SysUtils.Win32Platform = VER_PLATFORM_WIN32_NT then
// Windows NT, Windows 2000
hDevice := CreateFile('//./PhysicalDrive0', GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, , )
else
// Version Windows 95 OSR2, Windows 98
hDevice := CreateFile('//./SMARTVSD', , , nil, CREATE_NEW, , );
if hDevice = INVALID_HANDLE_VALUE then Exit;
try
FillChar(SCIP, SizeOf(TSendCmdInParams) - , #);
FillChar(aIdOutCmd, SizeOf(aIdOutCmd), #);
cbBytesReturned := ;
with SCIP do begin
cBufferSize := IDENTIFY_BUFFER_SIZE;
with irDriveRegs do begin
bSectorCountReg := ;
bSectorNumberReg := ;
bDriveHeadReg := $A0;
bCommandReg := $EC;
end;
end;
if not DeviceIoControl(hDevice, $0007C088, @SCIP, SizeOf(TSendCmdInParams) - ,
@aIdOutCmd, SizeOf(aIdOutCmd), cbBytesReturned, nil) then Exit;
finally
CloseHandle(hDevice);
end;
with PIdSector(@IdOutCmd.bBuffer)^ do begin
ChangeByteOrder(sSerialNumber, SizeOf(sSerialNumber));
(Pchar(@sSerialNumber) + SizeOf(sSerialNumber))^ := #;
Result := Pchar(@sSerialNumber);
end;
end; procedure TForm1.Button1Click(Sender: TObject);
var
stmp:String;
begin
//记得右击以管理员运行
stmp := StrPas(PAnsiChar(GetIdeSerialNumber));
if stmp<>'' then
begin
Memo1.Lines.Add('无参:' + stmp);
end
else
begin
stmp := Trim(GetScsiSerialNumber());
Memo1.Lines.Add('有参:' + stmp);
end;
end; end.

获得硬盘的ID序列号(XE10.1+WIN8.1)的更多相关文章

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

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

  2. C# 获取U盘ID序列号及U盘信息

    C# 获取U盘ID序列号及U盘信息 2011-05-20 上传大小:35KB c#VS2005U盘IDU盘信息   获取U盘ID序列号 VS2005编译通过,源码源自CSDN.已经测试好用. 可以获得 ...

  3. linux 下查看硬件信息(mac,IP地址,硬盘型号,序列号等)

    一.查看网卡mac地址 #安装lshw [root@server ~]# yum install lshw #使用方法 [root@rsync-server ~]# lshw -c network * ...

  4. 屏幕亮度(XE10.1+WIN8.164)

    相关资料: http://bbs.csdn.net/topics/390664310 实例代码: unit Unit1; interface uses Winapi.Windows, Winapi.M ...

  5. 屏幕相关操作(XE10.1+WIN8.164)

    相关资料: http://www.bianceng.cn/Programming/Delphi/201104/25455.htm http://blog.csdn.net/anbangs/articl ...

  6. asp.net中获取本机的相关信息!(CPU、内存、硬盘序列号等)

    // 注意:首先要在项目bin目录中添加引用 System.Management using System;using System.Collections.Generic;using System. ...

  7. 获得服务器硬件信息(CPUID、硬盘号、主板序列号、IP地址等)

    1 // 注意:首先要在项目中添加引用 System.Management using System; using System.Collections.Generic; using System.L ...

  8. 【miscellaneous】如何利用硬盘号和CPU序列号为软件加密

    原文:http://www.jiamisoft.com/blog/index.php/3469-yingpanhaocpuruanjianjiami.html 计算机软件是一种特殊的产品,为了防止软件 ...

  9. ThinkPad告别蓝快,自己使用VHD安 WIN8.1并成功激活

    写在前面:本文WIN8.1激活适合于中国大陆地区国行预装WIN8系统(bios写入WIN8授权)是可激活的,享受正版WIN8系统(同样可以安装WIN8.1系统).比如联想的Y400.Y500.Y480 ...

随机推荐

  1. Hbase—学习笔记(一)

    此文的目的: 1.重点理解Hbase的整体工作机制 2.熟悉编程api,能够用来写程序 1.  什么是HBASE 1.1.   概念特性 HBASE是一个数据库----可以提供数据的实时随机读写 HB ...

  2. Spring RabbitMQ 延迟队列

    一.说明 在实际业务场景中可能会用到延时消息发送,例如异步回调失败时的重发机制. RabbitMQ本身不具有延时消息队列的功能,但是可以通过rabbitmq-delayed-message-excha ...

  3. PR合并回写

    ) as LGORT ,'SAPRFC' as ERNAM,out_pr.due_datetime,out_pr.so_id,out_pr.so_lineid,out_pr.sobsl from V_ ...

  4. 清理数据库errorlog

    C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOGERRORLOGERRORLOG.1ERRORLOG.2ERRORLOG.3ERRORLO ...

  5. ArrayList LinkList比较

    1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构.      2.对于随机访问get和set,ArrayList优于LinkedList,因为ArrayLi ...

  6. 二叉树中的最大路径和 · Binary Tree Maximum Path Sum

    [抄题]: 给出一棵二叉树,寻找一条路径使其路径和最大,路径可以在任一节点中开始和结束(路径和为两个节点之间所在路径上的节点权值之和) [思维问题]: 不会写分合法 [一句话思路]: 用两次分治:ro ...

  7. centos7装NVIDIA显卡驱动

    一.系统及显卡 系统:centos7.5 64位 显卡:gtx 1060 前几天主要是有一个人脸识别的项目测试,需要用到显卡去测试性能,然后装显卡的过程折腾了一下,特此记录. 二.安装过程 1. 下载 ...

  8. discuz模板引擎语法

    论坛的首页模板:forum/discuz.htm 版块的内容模板:forum/forumdisplay.htm 主题的查看模板:forum/viewthread.htm 帖子的内容模板:forum/p ...

  9. EXP-00056:遇到oracle错误12154

    执行命令如下: 引用 exp user/pwd@dbname file=d:text.dmp owner=(user) 碰到了错误: 引用 EXP-00056:遇到oracle错误12154 ORA- ...

  10. Linux统计某文件夹下文件的个数

    ls -l |grep "^-"|wc -l 统计某文件夹下目录的个数 ls -l |grep "^d"|wc -l 统计文件夹下文件的个数,包括子文件夹里的 ...