在网上查到一段枚举出所有USB设备中找到U盘的代码,但不知道如何把设备与逻辑盘符对应起来?function SetupDiGetClassDevsA(ClassGuid: PGUID; const Enumerator: PAnsiChar;hwndParent: HWND; Flags: DWORD): HDEVINFO; stdcall;external 'SetupApi.dll';
function SetupDiEnumDeviceInfo(DeviceInfoSet: HDEVINFO;MemberIndex: DWORD; var DeviceInfoData: TSPDevInfoData): LongBool; stdcall;external 'SetupApi.dll';
function CM_Get_DevNode_Status(pulStatus: PULong; pulProblemNumber: PULong;dnDevInst: DWord; ulFlags: ULong): DWord; stdcall;external 'cfgmgr32.dll' name 'CM_Get_DevNode_Status';
function SetupDiGetDeviceRegistryPropertyA(DeviceInfoSet: HDEVINFO;const DeviceInfoData: TSPDevInfoData; Property_: DWORD;var PropertyRegDataType: DWORD; PropertyBuffer: PBYTE; PropertyBufferSize:DWORD;var RequiredSize: DWORD): LongBool; stdcall;external 'SetupApi.dll';
function CM_Request_Device_Eject(dnDevInst: DWord; out pVetoType: TPNPVetoType;pszVetoName: PChar; ulNameLength: ULong; ulFlags: ULong): DWord; stdcall;external 'SetupApi.dll' name 'CM_Request_Device_EjectA';//获得设备信息
function GetRegistryProperty(PnPHandle: hDevInfo; DevData:TSPDevInfoData; Prop: DWord; Buffer: PChar; dwLength: DWord): Boolean;
var
  aBuffer: array[0..256] of Char;
begin
  dwLength := 0;
  aBuffer[0] := #0;
  SetupDiGetDeviceRegistryPropertyA(PnPHandle, DevData, Prop, Prop,PBYTE(@aBuffer[0]), SizeOf(aBuffer), dwLength);
  StrCopy(Buffer, aBuffer);
  Result := Buffer^ <> #0;
end;//根据设备信息回复出设备的名称
function ConstructDeviceName(DeviceInfoSet: hDevInfo;DeviceInfoData:TSPDevInfoData; Buffer: PChar; dwLength: DWord): Boolean;
const
  UnknownDevice = '<Unknown Device>';
begin
  if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_FRIENDLYNAME, Buffer, dwLength)) then
  begin
    if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_DEVICEDESC, Buffer, dwLength)) then
    begin
      if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_CLASS, Buffer, dwLength)) then
      begin
        if (not GetRegistryProperty(DeviceInfoSet, DeviceInfoData, SPDRP_CLASSGUID, Buffer, dwLength)) then
        begin
          dwLength := DWord(SizeOf(UnknownDevice));
          Buffer := Pointer(LocalAlloc(LPTR, Cardinal(dwLength)));
          StrCopy(Buffer, UnknownDevice);
        end;
      end;
    end;
  end;
  Result := true;
end;//遍历DevInfo,获得U盘在当前系统设备列表中的ID
function EnumAddDevices(ShowHidden: Boolean;DevInfo: hDevInfo): Boolean;
var
  i, Status, Problem: DWord;
  pszText: PChar;
  DeviceInfoData:TSPDevInfoData;
begin
  DeviceInfoData.cbSize := SizeOf(TSPDevInfoData);
  i := 0;
  //遍历设备列表,查找USB存储设备信息
  while SetupDiEnumDeviceInfo(DevInfo, i, DeviceInfoData) do
  begin
    inc(i);
    //获取设备节点状态信息
    if (CM_Get_DevNode_Status(@Status, @Problem, DeviceInfoData.DevInst, 0) <> CR_SUCCESS) then
    begin
      break;
    end;
    try
      GetMem(pszText, 256);
      ConstructDeviceName(DevInfo, DeviceInfoData, pszText, DWord(nil)); //创建设备可见名称列表
      if pos('USB Mass Storage Device',StrPas(pszText))<>0 then     //比较字符串,找到USB存储设备
              MyDevice_ID:=i-1;  //得到USB存储设备在当前设备列表中的ID
             这里怎么知道USB存储设备的逻辑盘符呢?    
    finally
      FreeMem(pszText);
    end;
  end;
  Result := true;
end;//获取系统中所有设备信息到hDevInfo指针所指空间
function GetDevInfo(var hDevInfo:HDEVINFO): boolean;
begin
  hDevInfo := SetupDiGetClassDevsA(nil, nil, 0, DIGCF_PRESENT or DIGCF_ALLCLASSES);
  Result := hDevInfo <> Pointer(INVALID_HANDLE_VALUE);
end;//获得设备列表
procedure IniDevice;
begin
  MyDevice_ID:=0;
  DevInfo:= nil;
  if not GetDevInfo(DevInfo) then
    begin
      ShowMessage('枚举设备失败!');
      exit;
    end;
  EnumAddDevices(TRUE,DevInfo);
end;