samuelcampos / usbdrivedetector

A Java library to get a list of all usb storage devices connected to the computer.
MIT License
128 stars 46 forks source link

Is there any way to retreive Vendor ID and Product Id from removable devices? #27

Open sushiljic opened 4 years ago

sushiljic commented 4 years ago

I need to use verify the pendrive by its vendor ID and Product ID for its uniqueness so is there way to get VID and PID?

MarkJeronimus commented 4 years ago

Not with this library, but on linux you could execute 'lsusb' and see if the VID:PID is listed (the device and/or mount point will not be listed so there's no way to link anything if there are multiple identical pendrives attached.

samuelcampos commented 4 years ago

Do you need to identify the pendrive using the VID and PID specifically? Can't you use the Serial Number instead?

sushiljic commented 4 years ago

@samuelcampos I need vendor ID and product ID because It can't be changed easily whereas Serial Number can be changed and also It get changed when formatted. It is good library and It would be best if we can retrieve VID and PID too.

marian-m12l commented 4 years ago

@samuelcampos I need vendor ID and product ID because It can't be changed easily whereas Serial Number can be changed and also It get changed when formatted. It is good library and It would be best if we can retrieve VID and PID too.

Indeed. When expecting a specific device, one could make sure to find the mount point of that particular device. Library looks great anyway! :-)

Avec112 commented 1 year ago

If you already know what USB device that is used one way that is supported is to give the USB device a Volume Name and inside the code check for device.getDeviceName().equalsIgnoreCase("myVolumeName"). Also the mount point might not be that important since the device has a method which returns the root directory as a file. That would be device.getRootDirectory().

ouaibsky commented 1 year ago

maybe it can help you (only jdk21 with preview):