如何获取USB设备的序列号?

来源:互联网 发布:海马玩模拟器mac版删 编辑:程序博客网 时间:2024/05/17 02:46

比如联想A710e,用adb可以获取到其序列号是“A710e”:
D:\pcsuit\bin\Adb>adb devices
List of devices attached
A710e   device

如果用程序获取到其序列号呢?

该序列号在注册表项【HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\USB】下能找到!

但是,从注册里读取出来的序列号信息,不一定准确。
比如联想A68e的序列号里有空格,但注册表里把空格替换成下划线了:

但它实际的序列号是"A68e            "。
可以用usbview,通过DeviceIoControl()直接读取硬件设备信息,获取到的。
用adb.exe命令对它进行操作,也必须使用有空格的真实序列号,否则,操作是会失败的。如:
D:\pcsuite\bin\Adb>adb -s "A68e" shell am startservice -a skymobi_tcpservice
error: device not found
D:\pcsuite\bin\Adb>adb -s "A68e____________" shell am startservice -a skymobi_tcpservice
error: device not found
D:\pcsuite\bin\Adb>adb -s "A68e            " shell am startservice -a skymobi_tcpservice
Starting service: Intent { act=skymobi_tcpservice }