怎样得到U盘的出厂物理编号????????

我不要昵称 2005-11-07 09:13:57
怎样得到U盘的出厂物理编号????????
...全文
433 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
constantine 2005-11-09
  • 打赏
  • 举报
回复
没有试过,学习
ly_liuyang 2005-11-09
  • 打赏
  • 举报
回复
这个问题讨论过不知道多少次的
注册表就有的
SetupAPI获得的数据同注册表的一样的

_____________________
http://lysoft.7u7.net
何鲁青 2005-11-09
  • 打赏
  • 举报
回复
还是啊日牛,try一下
xylegend 2005-11-09
  • 打赏
  • 举报
回复
mark
我不要昵称 2005-11-08
  • 打赏
  • 举报
回复
做过U盘的看看啊
aiirii 2005-11-08
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

{
typedef struct _USB_DEVICE_DESCRIPTOR {
UCHAR bLength ;
UCHAR bDescriptorType ;
USHORT bcdUSB ;
UCHAR bDeviceClass ;
UCHAR bDeviceSubClass ;
UCHAR bDeviceProtocol ;
UCHAR bMaxPacketSize0 ;
USHORT idVendor ;
USHORT idProduct ;
USHORT bcdDevice ;
UCHAR iManufacturer ;
UCHAR iProduct ;
UCHAR iSerialNumber ;
UCHAR bNumConfigurations ;
}


const
DIGCF_PRESENT = 2;
DIGCF_INTERFACEDEVICE = 16;
type

PSP_DEVINFO_DATA = ^SP_DEVINFO_DATA;
SP_DEVINFO_DATA = packed record
cbSize :DWORD;
ClassGuid :TGUID;
DevInst :DWORD ; // DEVINST handle
Reserved :DWORD;
end;

HDEVINFO = Pointer;

pulong = ^ulong;

PSP_INTERFACE_DEVICE_DATA = ^SP_INTERFACE_DEVICE_DATA;
SP_INTERFACE_DEVICE_DATA = packed record
cbSize :ulong;
InterfaceClassGuid : TGuid;
Flags :ulong;
Reserved :ulong;
end;

PSP_INTERFACE_DEVICE_DETAIL_DATA = ^PSP_INTERFACE_DEVICE_DETAIL_DATA;
SP_DEVICE_INTERFACE_DETAIL_DATA = packed record
cbSize :DWORD;
DevicePath: Char;
end;


PUSB_DEVICE_DESCRIPTOR = ^USB_DEVICE_DESCRIPTOR;
USB_DEVICE_DESCRIPTOR = packed record
bLength :UCHAR;
bDescriptorType :UCHAR;
bcdUSB :WORD;
bDeviceClass :UCHAR;
bDeviceSubClass :UCHAR;
bDeviceProtocol :UCHAR;
bMaxPacketSize0 :UCHAR;
idVendor :Word;
idProduct :Word;
bcdDevice :Word;
iManufacturer :UCHAR;
iProduct :UCHAR;
iSerialNumber :UCHAR;
bNumConfigurations :UCHAR;
end;

function SetupDiGetDeviceInterfaceDetail(
DeviceInfoSet : HDEVINFO;
DeviceInterfaceData: PSP_INTERFACE_DEVICE_DATA;
DeviceInterfaceDetailData: PSP_INTERFACE_DEVICE_DETAIL_DATA;
DeviceInterfaceDetailDataSize : DWORD;
RequiredSize : PDWORD;
DeviceInfoData : PSP_DEVINFO_DATA
): BOOL; stdcall; external 'SETUPAPI.dll' name 'SetupDiGetDeviceInterfaceDetailA';

function SetupDiGetClassDevsEx(
ClassGuid :PGUID;
Enumerator :PChar;
hwndParent :HWND;
Flags : DWORD;
MachineName :PChar;
Reserved :Pointer
): HDEVINFO; stdcall; external 'SETUPAPI.dll' name 'SetupDiGetClassDevsExA';

function SetupDiGetClassDevs(
ClassGuid :PGUID ;
Enumerator: PChar;
hwndParent: HWND;
Flags : DWORD
): HDEVINFO; stdcall; external 'SETUPAPI.dll' name 'SetupDiGetClassDevsA';

function SetupDiEnumDeviceInterfaces(
DeviceInfoSet :HDEVINFO;
DeviceInfoData :PSP_DEVINFO_DATA;
InterfaceClassGuid :PGUID;
MemberIndex :DWORD;
DeviceInterfaceData :PSP_INTERFACE_DEVICE_DATA
): BOOL; stdcall; external 'SETUPAPI.dll' name 'SetupDiEnumDeviceInterfaces';

function SetupDiDestroyDeviceInfoList(
DeviceInfoSet :HDEVINFO
):BOOL; stdcall; external 'SETUPAPI.dll' name 'SetupDiEnumDeviceInterfaces';

type
TOnGetStrEvent = procedure(AStr :string) of object;

//以下代码可枚举所有设备

const //USBIODS_GUID : TGuid = '{745a17a0-74d3-11d0-b6fe-00a0c90f57da}';
USBIODS_GUID : TGuid = '{a5dcbf10-6530-11d2-901f-00c04fb951ed}';

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var b :integer;
bRst :BOOL;
hInfo :HDEVINFO;
// USBIODS_GUID :TGuid;
deviceInterfaceData :SP_INTERFACE_DEVICE_DATA;
DeviceDetailData :SP_DEVICE_INTERFACE_DETAIL_DATA;

predictedLength : ULONG;
requiredLength :ULONG;
nCount: integer;
begin
Memo1.Clear;

{ USBIODS_GUID.D1 := $a5dcbf10;
USBIODS_GUID.D2 := $6530;
USBIODS_GUID.D3 := $11d2;
USBIODS_GUID.D4[0] := $90;
USBIODS_GUID.D4[1] := $1f;
USBIODS_GUID.D4[2] := $00;
USBIODS_GUID.D4[3] := $c0;
USBIODS_GUID.D4[4] := $4f;
USBIODS_GUID.D4[5] := $b9;
USBIODS_GUID.D4[6] := $51;
USBIODS_GUID.D4[7] := $ed;
}
// USBIODS_GUID := '{a5dcbf10-6530-11d2-901f-00c04fb951ed}';

predictedLength := 0;
requiredLength := 0;
hInfo := nil;
hInfo := SetupDiGetClassDevs(@USBIODS_GUID, nil, 0,
DIGCF_PRESENT OR DIGCF_INTERFACEDEVICE);

bRst := true;
nCount := 0;

deviceInterfaceData.cbSize := Sizeof(SP_INTERFACE_DEVICE_DATA);
DeviceDetailData.cbSize := sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

if hInfo = nil then
begin
showmessage('failed 0');
exit;
end;

while bRst do
begin
deviceInterfaceData.cbSize := Sizeof(deviceInterfaceData);

bRst := SetupDiEnumDeviceInterfaces(hInfo, nil, @USBIODS_GUID,
nCount, @deviceInterfaceData);

if bRst then
begin
SetupDiGetDeviceInterfaceDetail(hInfo, @deviceInterfaceData,
nil, 0, @requiredLength, nil);


predictedLength := requiredLength;
DeviceDetailData.cbSize := sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
bRst := SetupDiGetDeviceInterfaceDetail(hInfo, @deviceInterfaceData,
@DeviceDetailData, predictedLength, @requiredLength, nil);

if bRst then
begin
// showmessage('ok'+inttostr(nCount));
///// pszDevicePath[nCount] := string(PChar(@(DeviceDetailData.DevicePath)));
showmessage(string(PChar(@(DeviceDetailData.DevicePath))));
//// Memo1.Lines.Add(pszDevicePath[nCount]);
// Memo1.Lines.Add(string(PChar(@(DeviceDetailData.DevicePath))));
Inc(nCount);
end;
end;
end; //end while
showmessage('finished');
// SetupDiDestroyDeviceInfoList(hInfo);
end;


end.
我不要昵称 2005-11-08
  • 打赏
  • 举报
回复
help
constantine 2005-11-07
  • 打赏
  • 举报
回复
没有搞过,gz
何鲁青 2005-11-07
  • 打赏
  • 举报
回复
关注,也想知道,因为想要搞一个监控U盘使用的程序,不知道U盘是不是也像硬盘那样有个ID号那?
我不要昵称 2005-11-07
  • 打赏
  • 举报
回复
SOS
我不要昵称 2005-11-07
  • 打赏
  • 举报
回复
用Delphi怎么写程序?????读取USB的物理序列号???????????
zengaaa 2005-11-07
  • 打赏
  • 举报
回复
你可以到
http://www.wbj3000.com/
网站上去下载【U盘检测器 v5.0】
它可以给你给出相应的数据!
我不要昵称 2005-11-07
  • 打赏
  • 举报
回复
up

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧