The key status returned from GetKeyState function changes as a specified thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information.
I have a problem. I have some USB flash media and i want to use it to store some key data for my software. The data are encrypted. In order to protect the media from direct copying i want to include Vendor ID, Product ID and serial number into the encryption key.
How to obtain VID, PID and serial?
I've tried two approaches:
1. Issue IOCTL_STORAGE_QUERY_PROPERTY on the drive in order to obtain STORAGE_DEVICE_DESCRIPTOR. It looked like these parameters are present in this structure. However looks like this works correctly only for SCSI. For IDE devices VendorID field is empty (NULL), ProductID field contains drive model string obtained via Identify command, SerialNo field is also empty. For USB drive the things are even worse: Vendor = "USB", Product = "Flash disk" and no serial number.
I've tried IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER, but on my flash drives it simply doesn't work. The documentation says it works only WinXP SP1 and only if the media is SCM-1 (Security content management)-compilant. That's all, approach no. 1 stopped here.
2. Traverse through a USB devices tree exactly in the same way as USBView does. Everything is okay, i see IDs and serials, but now i need to find out a drive letter under which the flash device is mounted from the hub name and port number? IOCTL_USB_GET_NODE_CONNECTION_NAME gives empty string on non-hubs. IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME works and gives me some ID, but what to do with it then?
Please help me.