使用wmiobject通过powershell以MTP模式浏览android设备的文件系统

时间:2015-01-22 15:27:42

标签: android powershell com mtp

我已经阅读了一些讨论如何使用PowerShell访问usb驱动器的帖子和文章:

但实际上没有一个"答案"这个问题。分享的最后一篇文章还说,由于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方式可以解决这个问题。我们该怎么做?

1 个答案:

答案 0 :(得分:0)

要在Power Shell中查找MTP设备,请使用以下命令:

Get-WmiObject -class win32_pnpentity -computername localhost | where-object {$_.HardwareID -like "*MTP*"} | format-list
  

Samsung Galaxy S5的输出示例

     

__GENUS : 2   __CLASS : Win32_PnPEntity   __SUPERCLASS : CIM_LogicalDevice   __DYNASTY : CIM_ManagedSystemElement   __RELPATH : Win32_PnPEntity.DeviceID="USB\\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\\6&8F62A49&0&0000"   __PROPERTY_COUNT : 24   __DERIVATION : {CIM_LogicalDevice, CIM_LogicalElement, CIM_ManagedSystemElement}   __SERVER : -*- Computer Name -*-   __NAMESPACE : root\cimv2   __PATH : \\-*- Computer Name -*-\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\\6&8F62A49&0&0000"   Availability :   Caption : -*- device display name in explorer -*-   ClassGuid : {eec5ad98-8080-425f-922a-dabf3de3f69a}   CompatibleID : {USB\MS_COMP_MTP, USB\Class_06&SubClass_01&Prot_01, USB\Class_06&SubClass_01, USB\Class_06...}   ConfigManagerErrorCode : 0   ConfigManagerUserConfig : False   CreationClassName : Win32_PnPEntity   Description : SM-G900P   DeviceID : USB\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\6&8F62A49&0&0000   ErrorCleared :   ErrorDescription :   HardwareID : {USB\VID_04E8&PID_6860&REV_0400&MS_COMP_MTP&SAMSUNG_Android, USB\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_Android, USB\SAMSUNG_MOBILE&MS_COMP_MTP&SAMSUNG_Android, USB\SAMSUNG_MOBILE&MI_00...}   InstallDate :   LastErrorCode :   Manufacturer : Samsung Electronics Co., Ltd.   Name : -*- device display name in explorer -*-   PNPDeviceID : USB\VID_04E8&PID_6860&MS_COMP_MTP&SAMSUNG_ANDROID\6&8F62A49&0&0000   PowerManagementCapabilities :   PowerManagementSupported :   Service : WUDFRd   Status : OK   StatusInfo :   SystemCreationClassName : Win32_ComputerSystem   SystemName : -*- Computer Name -*-