title: Delphi - How to get list of USB removable hard drives and memory sticks?
body: <p>In my application (Delphi), I need to list all the USB storage devices. These can be either flash memory sticks <em>or</em> external storage drives. </p>
  
  <p>There is a <code>Jvcl</code> component <code>JvDriveCombo</code>, and it has the <code>DriveType</code> property - the problem is if I select <code>DriveType := Fixed</code> then in addition to the external drive, it also lists the internal drives (<code>C:\</code>, <code>D:\</code> etc). However, I only want to list the external drives. </p>
  
  <p>I believe there is DeviceIoControl function (I saw it on MSDN) but I have no idea of how to use it. </p>
  
  <p>I wonder if anyone can help me with the proper way / code to list USB storage devices?</p>
  
  <p>Thanks. </p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>I just found some sample code and am posting it here:</p>
  
  <pre><code>uses .... jwawinbase, JwaWinIoctl;
  
  procedure TForm1.Button1Click(Sender: TObject);
  var
    DriveCmdStr: string;
    DriveHandle: THandle;
    ADriveLetter: string;
    hp: STORAGE_HOTPLUG_INFO;
    rlen: DWORD;
  begin
  
    ADriveLetter := 'H';
    DriveCmdStr := Format('\\.\%s:', [ADriveLetter]);
    DriveHandle := CreateFile(PChar(DriveCmdStr), GENERIC_READ, FILE_SHARE_WRITE,
      nil, OPEN_EXISTING, 0, 0);
  
    if DriveHandle = INVALID_HANDLE_VALUE then
      Exit;
  
    DeviceIoControl(DriveHandle, IOCTL_STORAGE_GET_HOTPLUG_INFO, nil, 0, @hp,
      SizeOf(hp), @rlen, nil);
  
    CloseHandle(DriveHandle);
  
    if hp.MediaRemovable then
      showmessage('media removable');
  
  end;
  </code></pre>
  
  <p>Now I would like to just know how to enumerate all the drive letters. Which is the most efficient function? </p>