日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

windows c语言 sata 序列号,【Delphi】获取IDE/SATA硬盘序列号

發(fā)布時(shí)間:2023/12/14 windows 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 windows c语言 sata 序列号,【Delphi】获取IDE/SATA硬盘序列号 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

網(wǎng)上有這種代碼了,只是因?yàn)閷?xiě)的較早,有些地方寫(xiě)的不那么言簡(jiǎn)意賅,而且在XE后的版本中有問(wèn)題(因?yàn)閁nicode字符的關(guān)系)

下面是精簡(jiǎn)修改過(guò)的代碼,只取第一塊硬盤(pán)的序列號(hào),Win7 + XE 測(cè)試通過(guò)。需要先安裝JwApi函數(shù)庫(kù),因?yàn)橛行┙Y(jié)構(gòu)體在庫(kù)中有聲明了

unit uGetHDSN;

interface

uses

Windows, JwaWinIoctl;

function GetIdeSerialNumber: AnsiString;

implementation

type

TIdSector = packed record

wGenConfig: USHORT;

wNumCyls: USHORT;

wReserved: USHORT;

wNumHeads: USHORT;

wBytesPerTrack: USHORT;

wBytesPerSector: USHORT;

wSectorsPerTrack: USHORT;

wVendorUnique: array [0 .. 2] of USHORT;

sSerialNumber: array [0 .. 19] of AnsiChar;

wBufferType: USHORT;

wBufferSize: USHORT;

wECCSize: USHORT;

sFirmwareRev: array [0 .. 7] of AnsiChar;

sModelNumber: array [0 .. 39] of AnsiChar;

wMoreVendorUnique: USHORT;

wDoubleWordIO: USHORT;

wCapabilities: USHORT;

wReserved1: USHORT;

wPIOTiming: USHORT;

wDMATiming: USHORT;

wBS: USHORT;

wNumCurrentCyls: USHORT;

wNumCurrentHeads: USHORT;

wNumCurrentSectorsPerTrack: USHORT;

ulCurrentSectorCapacity: ULONG;

wMultSectorStuff: USHORT;

ulTotalAddressableSectors: ULONG;

wSingleWordDMA: USHORT;

wMultiWordDMA: USHORT;

bReserved: array [0 .. 127] of Byte;

end;

PIdSector = ^TIdSector;

const

IDE_ATA_IDENTIFY = $EC;

function LittleToBig(Data: Word): Word;

asm

xchg ah, al

end;

function GetIdeSerialNumber: AnsiString;

var

hDevice: THandle;

Size, cbBytesReturned: DWORD;

SCIP: TSendCmdInParams;

SCOP: PSendCmdOutParams;

P: PWORD;

I: Integer;

begin

Result := '';

hDevice := CreateFile('\\.\PhysicalDrive0', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or

FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);

if hDevice = INVALID_HANDLE_VALUE then

Exit;

Size := SizeOf(TSendCmdOutParams) + IDENTIFY_BUFFER_SIZE - 1;

SCOP := AllocMem(Size);

SCIP.irDriveRegs.bCommandReg := IDE_ATA_IDENTIFY;

if DeviceIoControl(hDevice, SMART_RCV_DRIVE_DATA, @SCIP, SizeOf(TSendCmdInParams) - 1, SCOP, Size,

cbBytesReturned, nil) = False then

begin

FreeMem(SCOP);

CloseHandle(hDevice);

Exit;

end;

// 處理一下序列號(hào)在內(nèi)存中的順序

with PIdSector(@SCOP^.bBuffer[0])^ do

begin

SetLength(Result, Length(sSerialNumber));

P := @Result[1];

CopyMemory(P, @sSerialNumber[0], Length(sSerialNumber));

for I := 1 to Length(sSerialNumber) div 2 do

begin

P^ := LittleToBig(P^);

Inc(P);

end;

end;

FreeMem(SCOP);

end;

end.

總結(jié)

以上是生活随笔為你收集整理的windows c语言 sata 序列号,【Delphi】获取IDE/SATA硬盘序列号的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。