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. zabbix出现中文不能选的情况

    像这里一样,有些选项是选不了的,这个时候我们要做的第一步就是,找到这个配置文件. 如果不知道在哪里的话可以用find命令查找. sudo find / -name locales.inc.php 找到 ...

  2. [Fiddler] The connection to 'xxxxx.com' failed. <br />System.Security.SecurityException Failed to negotiate HTTPS connection with server.fiddler.network.https&gt; HTTPS handshake to intelte

    最近利用模拟发get请求的时候出现: [Fiddler] The connection to ‘xxxxx.com' failed. <br />System.Security.Secur ...

  3. Spring AsyncRestTemplate

    类说明 AsyncRestTemplate 是 Spring中提供异步的客户端HTTP访问的核心类.与RestTemplate类相似,它提供了一些类似的方法,只不过返回类型不是具体的结果,而是List ...

  4. IE低版本浏览器兼容问题

    head标签中填写如下代码 <meta name="renderer" content="webkit"/> <meta name=" ...

  5. Spring/AOP框架, 以及使用注解

    1, 使用代理增加日志, 也是基于最原始的办法 import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; ...

  6. phpStudy7——MySql数据库的增删查改

    1. 添加数据: //添加数据 $strsql = "insert into user_info(userId,userName,phoneNumber,userScore,dataTime ...

  7. 复杂度分析 quick sort&merge sort

    空间复杂度看新开了什么数据结构就够了 公式=几个点*每个点执行了多少次 二叉树都是n次 二分法查找:lgn 全部查找:n n:找一个数,但是两边都要找.相当于遍历.类似于rotated sorted ...

  8. centos6.6 下 安装 nginx

    1.安装nginx需要pcre的依赖,请安装好pcre.假设安装目录如下: /usr/local/pcre-8.38 源码目录如下: /usr/src/pcre-8.38 2.下载nginx安装压缩包 ...

  9. phpstorm2018.3的安装和激活和汉化

    安装 第一步:解压并打开文件,运行安装程序,点击Next进入下一步, 第二步:选择软件安装目录,自定义选择安装根目录--> 注意!后面还需要找安装目录里的文件,所以记住安装到一个比较容易查看的目 ...

  10. Laravel 本地化定义

    1.配置本地化语言Laravel 的本地化语言配置项位于config/app.php: [php] view plain copy 'locale' => 'zh',//当前语言 'fallba ...