问题描述
如何从驱动器号获取设备实例ID?
How do I get from a drive letter to a device instance ID?
我的过程从设备到达消息开始.我已经成功从到达消息中获取驱动器号并打开了DVD托盘.
My process starts with a device arrival message. I have been successful in getting the drive letter from the arrival message and in opening the dvd tray.
我搜索了各种Setup API项目;但是我还没有发现任何让我从驱动器号到设备实例ID的东西.
I have searched the various Setup API items; but I haven't found anything that gets me from a drive letter to a device instance ID.
使用C#或VB.NET的解决方案是理想的,但是只要我能看到API调用,我愿意从任何其他语言中找出答案.
A solution in C# or VB.NET would be ideal, but I'm willing to figure it out from any other language as long as I can see the API calls.
预先感谢...
推荐答案
您不能直接这样做.
链接将使用STORAGE_DEVICE_NUMBER
.您可以在设备名称上使用带IOCTL_STORAGE_GET_DEVICE_NUMBER
的DeviceIoControl来填充此结构.将此值放在一侧.
然后,您需要使用SetupDiGetClassDevs
将GUIDS设置为适当的,以获取系统上的设备信息,指示您已插入的驱动器.然后使用SetupDiEnumDeviceInfo
枚举设备.然后使用SetupDiEnumDeviceInterfaces
枚举接口,最后使用SetupDiGetDeviceInterfaceDetail
获取信息.在返回的此结构中,您可以获得一个DevicePath,可以使用它来获取上述的STORAGE_DEVICE_NUMBER
.将其与驱动器号中的STORAGE_DEVICE_NUMBER
匹配,现在您已将驱动器号链接到您的结构. !该结构内部是一个DevInst.
The link is to use STORAGE_DEVICE_NUMBER
. You can use DeviceIoControl with IOCTL_STORAGE_GET_DEVICE_NUMBER
on your device name to populate this structure. Put this value to one side.
You then need to get device infomation on your system using SetupDiGetClassDevs
setting the GUIDS as approriate, indicicating the drives your are insterested in. Then enumerate through the devices using SetupDiEnumDeviceInfo
. Then enumerate the interfaces using SetupDiEnumDeviceInterfaces
and finally get the information using SetupDiGetDeviceInterfaceDetail
. In this structure returned you can get a DevicePath you can use to get the STORAGE_DEVICE_NUMBER
as above. Match this with the STORAGE_DEVICE_NUMBER
from your drive letter, and you have now linked a driver letter to your structure. Phew! Inside this structure is a DevInst.
这篇关于驱动器号到设备实例ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!