我浏览了几篇讨论如何使用 powershell 访问 USB 驱动器的帖子和文章,例如:
但他们都没有真正“回答”这个问题。最后分享的帖子还说,由于 MTP(协议)本身具有某些限制,没有人创建过 MTP 解决方案。
我走的一条路线有点碰壁;我不知道下一步该做什么(使用 wmi 对象)。我使用了以下 vbscript 程序,并记下了我感兴趣的设备的设备 ID 从这里获得:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDevices = objWMIService.ExecQuery _
("Select * From Win32_USBControllerDevice")
For Each objDevice in colDevices
strDeviceName = objDevice.Dependent
strQuotes = Chr(34)
strDeviceName = Replace(strDeviceName, strQuotes, "")
arrDeviceNames = Split(strDeviceName, "=")
strDeviceName = arrDeviceNames(1)
Set colUSBDevices = objWMIService.ExecQuery _
("Select * From Win32_PnPEntity Where DeviceID = '" & strDeviceName & "'")
For Each objUSBDevice in colUSBDevices
Wscript.Echo objUSBDevice.Description
Next
Next
我已经在下面的 powershell 命令中插入了它来获取 wmi 对象:
Get-WmiObject win32_pnpentity -filter "DeviceID='<the_device_id>'"
现在我想我有 WMI 对象。但我能用它做什么。
从我链接到的上一篇文章中,我有一种预感,有一种 COM 方法可以处理这个问题。我们必须如何做到这一点?