如何取U盘的VID和PID? ( 积分: 100 )

  • 主题发起人 主题发起人 netfun2000
  • 开始时间 开始时间
N

netfun2000

Unregistered / Unconfirmed
GUEST, unregistred user!
我想取U盘(不是移动硬盘)的VID和PID,如何取?
 
这个我也想知道,帮你顶一下
 
真想了解的话:
http://community.csdn.net/Expert/topic/4984/4984863.xml?temp=.9372827
要去www.delphi-jedi.org下载SetupAPI和Hid单元
 
ftp://ftp.delphi-jedi.org/api/hid.zip
ftp://ftp.delphi-jedi.org/api/SetupAPI.zip
 
我用hid里面的DEMO测试,报错:
Access violation at address 6F88123F in module 'hid.dll'.Read of address FFFFFFFF0
 
unit Unit1;

interface

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

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

const MAX_DETAIL_BUFF_LEN = 256;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var MyGuid : TGUID;
hHDEVINFO : HDEVINFO;
MyInterface : TSPDeviceInterfaceData;
bSuccess : Boolean;
MyDetail : array[0..MAX_DETAIL_BUFF_LEN-1] of byte;
PMyDetail : PSPDeviceInterfaceDetailData;
begin
//这个是正确的guid:A5DCBF10-6530-11D2-901F-00C04FB951ED
MyGuid.D1 := $A5DCBF10;
MyGuid.D2 := $6530;
MyGuid.D3 := $11D2;
MyGuid.D4[0]:= $90;
MyGuid.D4[1]:= $1F;
MyGuid.D4[2]:= $00;
MyGuid.D4[3]:= $C0;
MyGuid.D4[4]:= $4F;
MyGuid.D4[5]:= $B9;
MyGuid.D4[6]:= $51;
MyGuid.D4[7]:= $ED;
hHDEVINFO := SetupDiGetClassDevs(@MyGuid, nil, 0, DIGCF_DEVICEINTERFACE+DIGCF_PRESENT);
if (DWORD(hHDEVINFO) <> INVALID_HANDLE_VALUE) then
begin
MyInterface.cbSize := sizeof(TSPDeviceInterfaceData);
bSuccess := SetupDiEnumDeviceInterfaces(hHDEVINFO, nil, MyGuid, 0, MyInterface);
if not bSuccess then
SetupDiDestroyDeviceInfoList(hHDEVINFO)
else
begin
ZeroMemory(@MyDetail, MAX_DETAIL_BUFF_LEN);
PMyDetail := @MyDetail;
PMyDetail.cbSize := sizeof(TSPDeviceInterfaceDetailData);
if not SetupDiGetDeviceInterfaceDetail(hHDEVINFO,@MyInterface, @MyDetail, MAX_DETAIL_BUFF_LEN, nil, nil) then
SetupDiDestroyDeviceInfoList(hHDEVINFO)
else
ShowMessage(StrPas(PMyDetail.DevicePath));
end;
end;
end;


end.
测试没有通过。
 
上面得到的不对。
 
用JEDI的测不出来!
 
再提,
再加点分(好的帖子到下面领分):
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3657680
 
不知道网络上的那个U盘工具是怎么做出来的。
 
后退
顶部