【发布时间】:2015-01-22 15:27:42
【问题描述】:
我浏览过一些讨论如何使用 powershell 访问 USB 驱动器的帖子和文章,例如:
- Browse files on camera using PowerShell
- List all devices, partitions and volumes in Powershell
- https://superuser.com/a/377008/9546
但他们都没有真正“回答”这个问题。上一篇分享的帖子还说,由于 MTP(协议)本身具有某些限制,没有人创建过 MTP 解决方案。
我走的一条路线有点碰壁;我不知道下一步该做什么(使用 wmi 对象)。我使用了下面的 vbscript 程序,并记下了我感兴趣的设备的设备 id 从here 获得:
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 方法可以处理这个问题。我们该怎么做?
【问题讨论】:
标签: android powershell com mtp