title: How to get information on the drive where the executable is located in c++
body: <p>My app will be running from a USB key which have specific information like vendor-id, device-id, ... which I need.</p>
  
  <p>I tried using libusb, but despite the fact that I still can't make it work properly, how could I find the right usb drive to get information from?</p>
  
  <p>Note that I would like the code to be cross-platform, that's why I firstly choose libusb.</p>
  
  <p>Edit :</p>
  
  <p>I have found a program (usbviewer) that enumerates all usb ports and the specific informations on the drive when it's connected.</p>
  
  <p>I have read the sources for linux, infos are directly extracted from /proc/bus/usb/devices, it's quite straightforward.</p>
  
  <p>But on windows, to get usb node connection information, it takes about 1000 lines before you get the actual information in a data structure (enumerate hub controllers, root hubs, ports...).</p>
  
  <p>libusb on the otherside force me to generate an INF file and install a driver via inf-wizard.exe for each device before I can reach the information (didn't try on linux though).</p>
  
  <p>Edit 2 :</p>
  
  <p>I have found a way to get the device serial number with Windows, Linux and Mac OS X (didn't try MAC OS X but it should work just as Linux). For Windows, I use the function <code>GetVolumeInformation()</code>, on Linux, to read the serial number of drives with a FAT filesystem, I read 4 bytes in the corresponding /dev/* file starting from 0x27 or 0x43 depending on the FAT version.</p>
  
  <p>But this reading requieres a root access which the program won't have, and it seems to me a little bit unreliable.</p>
  
  <p>Any ideas ?</p>