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. Windows驱动手动卸载与安装

    彻底卸载的流程 1.删除C:\windows\inf\oem.inf路径下的所有oem文件 2.删除c:\windows\system32\drivers路径下对应的sys文件 3.(重要) 第一步: ...

  2. HttpClient 超时时间

    setSoTimeout(MilSec):连接超时时间.如果在连接过程中有数据传输,超时时间重新计算. setConnectTimeout(MilSec):获取连接超时时间.如果该参数没有设置,那么默 ...

  3. mysql数据库的卸载

    1.控制面板    程序和功能  卸载MySQL相关 2.卸载MySQL的安装目录  与储存目录 3.删除C盘下隐藏MySQL文件:组织-----文件夹和搜索选项-----------查看------ ...

  4. golang interface接口

    package main import "fmt" type Shaper interface { Area() float32 } type Square struct { si ...

  5. cdoj第13th校赛初赛F - Fabricate equation

    http://acm.uestc.edu.cn/#/contest/show/54 F - Fabricate equation Time Limit: 3000/1000MS (Java/Other ...

  6. 树莓派项目——基于树莓派的WIFI网络互传系统设计

    一 实验原理 所需硬件:树莓派3B,TP-LINK WiFi模块,笔记本电脑,网线 所需软件:Putty.远程桌面链接.python.cmd界面 树莓派3B是只有信用卡大小的微型电脑,其系统基于Lin ...

  7. DOS中符号的英文对照

    --------------siwuxie095 1..:point 或 dot 或 period 或 full stop 2.空格:space 或 blank ------------------- ...

  8. 3.滑雪-深搜&dp

    //Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道载一个区域中最长底滑 ...

  9. .NET中CORS跨域访问WebApi

    我这里只写基本用法以作记录,具体为什么看下面的文章: http://www.cnblogs.com/landeanfen/p/5177176.html http://www.cnblogs.com/m ...

  10. [Selenium] CSS3 选择器

    在 CSS 中,选择器是一种模式,用于选择需要添加样式的元素. "CSS" 列指示该属性是在哪个 CSS 版本中定义的.(CSS1.CSS2 还是 CSS3.) 选择器 例子 例子 ...