简体   繁体   English

如何获得特定USB设备的编程序列号和其他详细信息?

[英]How to achieve programmatic serial number and other details of a specific USB device?

How can I get information about specific USB? 如何获得有关特定USB的信息? Information such as serial number, manufacturer number, product number, etc. 信息,例如序列号,制造商编号,产品编号等。

I can get the handle to USB by this func 我可以通过此功能获取USB手柄

CreateFile(L"\\\\.\\E:", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);

But from now on I'm pretty stuck, HidD_GetHidGuid , returns only Details of the hard disk,and GetRawInputDeviceList and GetRawInputDeviceInfo not allow me to get information about USB (by name, as in the example with the function CreateFile ) 但是从现在起,我很受困HidD_GetHidGuid仅返回硬盘的详细信息,并且GetRawInputDeviceListGetRawInputDeviceInfo不允许我获取有关USB的信息(按名称,例如具有CreateFile函数的示例)

When I try the following code: 当我尝试以下代码时:

DeviceIoControl(HandelUsb, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dg, sizeof(DISK_GEOMETRY),&dwReturned, NULL);
MEDIA_SERIAL_NUMBER_DATA msnd = { 0 };
DeviceIoControl(HandelUsb, IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER, NULL, 0, &msnd,sizeof(MEDIA_SERIAL_NUMBER_DATA), &dwReturned, NULL);

I always get a serial number 0 ... (I tried on different USB devices) 我总是得到一个序列号0 ...(我在其他USB设备上尝试过)

You could use SetupDi functions. 您可以使用SetupDi函数。 Take look on SetupDiGetClassDevs function which will return all attached devices. 看一下SetupDiGetClassDevs函数,它将返回所有连接的设备。 For USB devices use "USB" enumerator. 对于USB设备,请使用“ USB”枚举器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM