본문 바로가기
IT정보/하드웨어

델파이 USB 및 하드디스크 모든정보 읽어보기

by MonoSoft 2021. 8. 21.
728x90
반응형

델파이 USB 및 하드디스크 모든정보 읽어보기

 

{$APPTYPE CONSOLE}

 

uses

Windows, Messages, SysUtils, Variants;

 

type

PHIDDAttributes = ^THIDDAttributes;

HIDD_ATTRIBUTES = record

Size: ULONG; // size of structure (set before call)

VendorID: Word;

ProductID: Word;

VersionNumber: Word;

//

// Additional fields will be added to the end of this structure.

//

end;

THIDDAttributes = HIDD_ATTRIBUTES;

THIDUSBDeviceInfo = Record { contains interface level information of each device}

SymLink : String;

BufferSize : Word;

Handle : THandle;

VID : DWord;

PID : DWord;

VersionNumber : Word;

ManufacturerString : String;

ProductString : String;

SerialNumberString : String;

end;

 

function GetVolumeNameForVolumeMountPointW(const lpszVolumeMountPoint: LPCWSTR;

lpszVolumeName: LPWSTR; cchBufferLength: DWORD): BOOL; stdcall;

external kernel32;

 

function HidD_GetAttributes(HidDeviceObject: THandle;

var HidAttrs: THIDDAttributes): LongBool; stdcall;external 'hid.dll' name 'HidD_GetAttributes';

function HidD_GetManufacturerString(HidDeviceObject: THandle;

Buffer: PWideChar; BufferLength: Integer): LongBool; stdcall;external 'hid.dll' name 'HidD_GetManufacturerString';

function HidD_GetProductString(HidDeviceObject: THandle;

Buffer: PWideChar; BufferLength: Integer): LongBool; stdcall;external 'hid.dll' name 'HidD_GetProductString';

function HidD_GetSerialNumberString(HidDeviceObject: THandle;

Buffer: PWideChar; BufferLength: Integer): LongBool; stdcall;external 'hid.dll' name 'HidD_GetSerialNumberString';

 

function GetVolumeName(Name: string): string;

var

Volume: array [0..MAX_PATH] of Char;

begin

FillChar(Volume[0], SizeOf(Volume), 0);

GetVolumeNameForVolumeMountPointW(PChar(Name), @Volume[0], SizeOf(Volume));

Result := Volume;

end;

 

 

Function GetHidDeviceInfo( Symlink : PChar) : THIDUSBDeviceInfo;

Var

pstr : pWideChar;

DevHandle : THandle;

HidAttrs : THIDDAttributes;

Begin

FillChar(Result, SizeOf( Result), 0);

Result.SymLink := SymLink+ #0;

GetMem( pstr, 512);

DevHandle := CreateFile( Symlink,

GENERIC_READ or GENERIC_WRITE,

FILE_SHARE_READ or FILE_SHARE_WRITE,

nil,

OPEN_EXISTING,

0,

0);

 

If DevHandle <> INVALID_HANDLE_VALUE then

begin

If HidD_GetAttributes( DevHandle,HidAttrs) then

begin

result.VID := HidAttrs.VendorID;

result.PID := HidAttrs.ProductID;

result.VersionNumber := HidAttrs.VersionNumber;

end;

 

If HidD_GetManufacturerString( DevHandle, pstr, 512) then

Result.ManufacturerString := pStr;

If HidD_GetProductString( DevHandle, pstr, 512) then

Result.ProductString := pStr;

If HidD_GetSerialNumberString( DevHandle, pstr, 512) then

Result.SerialNumberString := pStr;

closeHandle( DevHandle);

end;

FreeMem( pStr);

End;

procedure Main;

var

VolumeName: string;

info: THIDUSBDeviceInfo;

begin

VolumeName:=GetVolumeName('i:\'); //assuming that I: is a USB drive

info:=GetHidDeviceInfo(pchar(VolumeName));

Writeln(info.SerialNumberString);

end;

 

begin

Main;

Readln;

end.

728x90
반응형

댓글