【发布时间】:2015-11-18 15:51:32
【问题描述】:
我正在尝试编写能够读取有关 REMOVEABLE_DEVICE (USB) 的一些信息的小程序。我试过pyusb,但我无法提取我需要的数据。
我想从系统中读取 USB 设备的名称。
采用这种格式:
USB Flash Memory - this is the model information
Removable Disk (H:) - this is the name of device
Generic Flash Disk
USB DISK (F:)
Lexar USB Flash Drive
Lexar (I:)
我可以通过 win32com.client 库获取型号信息,灵感来自 here,但我无法获取 Windows 资源管理器中显示的设备名称。
也许我使用了错误的库?
这是我的代码:
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_DiskDrive WHERE InterfaceType = \"USB\"")
for objItem in colItems:
if objItem.Caption != None:
print "Caption:" + ` objItem.Caption[:-11]`
这里是 Windows Win32_DiskDrive 类的链接:link
提前感谢您的帮助。
【问题讨论】: