D
D
DVamp1r32013-05-06 16:58:52
C++ / C#
DVamp1r3, 2013-05-06 16:58:52

USB. Find disk label by serial number

A trivial task: we connect a USB drive in Windows, a shortcut is displayed on the desktop.
At the moment, I learn about connecting the device through the WM_DEVICECHANGE message. Accordingly, I get the DEV_BROADCAST_DEVICEINTERFACE and DEV_BROADCAST_HDR structures . The question is, how to find out the disk label associated with the device, based on what I have? I dug in the direction of the DeviceIoControl function, but no matter how I turned it, I got error 50 (incorrect request). I also considered the option to store disk labels in the wchar_t array, and when connected, go through the list of devices and find out which letter is added, but this option seems to me not quite elegant =)

ZY . Through CreateFile I get the device descriptor:
// rawPath = L"\\?\USB#VID_0951&PID_1625#0019E06B0845A93187600199#{a5dcbf10-6530-11d2-901f-00c04fb951ed}" HANDLE hf = CreateFile(rawPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
In general, I did it to work with DeviceIoControl, but suddenly there is a method to do without this function using the HANDLE of the device.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Flexz, 2013-05-06
@DVamp1r3

Detecting Media Insertion or Removal - isn't it?
You can also get detailed information about disks via WMI: Win32_LogicalDisk .

D
DVamp1r3, 2013-05-06
@DVamp1r3

--

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question