Find which drive corresponds to which USB mass storage device in WinXP

后端 未结 2 1258
野的像风
野的像风 2020-12-08 17:53

I have several USB drives connected to a WinXP SP3 computer, and I need to tell them apart programatically - I need to find which drive letter corresponds to which d

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 17:56

    There is an official API to do this. See this sample: http://www.codeproject.com/KB/system/RemoveDriveByLetter.aspx

    The principle is that each storage volume on Windows is assigned a global number. First, you ask your drive for its number (by opening "\X:" and sending a IOCTL_STORAGE_GET_DEVICE_NUMBER request). Second, you go over all disk devices and ask each one for its number (by opening it, through a different path, so you can't just string-compare).

    Once you find a disk device carrying the same number as you queried your drive, you know you have a winner.

提交回复
热议问题