Danyfirex

Get Portable Devices

3 posts in this topic

Well an Implementation of IPortableDeviceManager Interface to get all Portable Device conected to our pc.

 

#include <Array.au3>
#include <WinAPICom.au3>
Opt("MustDeclareVars", 1)

Global Const $sCLSID_PortableDeviceManager = "{0af10cec-2ecd-4b92-9581-34f6ae0637f3}"
Global Const $sIID_IPortableDeviceManager = "{a1567595-4c2f-4574-a6fa-ecef917b9a40}"
Global Const $sTagIPortableDeviceManager = "GetDevices hresult(ptr;dword*); RefreshDeviceList hresult(); " & _
        "GetDeviceFriendlyName hresult(wstr;wstr;dword*); GetDeviceDescription hresult(wstr;wstr;dword*); " & _
        "GetDeviceManufacturer hresult(wstr;wstr;dword*); GetDeviceManufacturer hresult(wstr;wstr;ptr;dword*dword*); " & _
        "GetPrivateDevices hresult(ptr;dword*)"

Global Enum $eDevID, $eDevName, $eDevManufacturer, $eDevDescription


Local $aPnPDevices = GetPortableDevices()
If IsArray($aPnPDevices) Then _ArrayDisplay($aPnPDevices)

;~ Success: Return 0
;~ Failure: Return 2DArray [n][4] |;[n][0]$eDevID, [n][1]$eDevName, [n][2]$eDevManufacturer,[n][3] $eDevDescription
Func GetPortableDevices()
    Local $aDevicesInfo[0][0] ;[n][0]$eDevID, [n][1]$eDevName, [n][2]$eDevManufacturer,[n][3] $eDevDescription
    Local $oPortableDeviceManager = 0
    Local $SizeofArray = 0
    Local $hr = 0x80004005 ;E_Fail Just to Initialized <0
    Local $taPnPDeviceIDs = 0
    Local $tName = 0
    $oPortableDeviceManager = ObjCreateInterface($sCLSID_PortableDeviceManager, $sIID_IPortableDeviceManager, $sTagIPortableDeviceManager)
    If Not IsObj($oPortableDeviceManager) Then Return 0

    If FAILED($oPortableDeviceManager.GetDevices(Null, $SizeofArray)) Then Return 0
    If $SizeofArray < 1 Then Return 0
    $taPnPDeviceIDs = DllStructCreate("ptr[" & $SizeofArray & "]")
    If FAILED($oPortableDeviceManager.GetDevices(DllStructGetPtr($taPnPDeviceIDs), $SizeofArray)) Then Return 0

    ReDim $aDevicesInfo[$SizeofArray][4]

    For $i = 0 To $SizeofArray - 1
        $tName = DllStructCreate("wchar[512]", DllStructGetData($taPnPDeviceIDs, 1, $i + 1))
        $aDevicesInfo[$i][$eDevID] = DllStructGetData($tName, 1)
        $aDevicesInfo[$i][$eDevName] = _GetFriendlyName($oPortableDeviceManager, $aDevicesInfo[$i][$eDevID])
        $aDevicesInfo[$i][$eDevManufacturer] = _GetDeviceManufacturer($oPortableDeviceManager, $aDevicesInfo[$i][$eDevID])
        $aDevicesInfo[$i][$eDevDescription] = _GetDeviceDescription($oPortableDeviceManager, $aDevicesInfo[$i][$eDevID])
        $tName = 0
        _WinAPI_CoTaskMemFree(DllStructGetData($taPnPDeviceIDs, 1, $i + 1))
    Next
    Return $aDevicesInfo

EndFunc   ;==>GetPortableDevices



Func _GetDeviceManufacturer($oInterface, $PnPDeviceID)
    Local $sString = ""
    $oInterface.GetDeviceManufacturer($PnPDeviceID, $sString, 128)
    Return $sString
EndFunc   ;==>_GetDeviceManufacturer


Func _GetDeviceDescription($oInterface, $PnPDeviceID)
    Local $sString = ""
    Local Const $Size = 128
    $oInterface.GetDeviceDescription($PnPDeviceID, $sString, 128)
    Return $sString
EndFunc   ;==>_GetDeviceDescription


Func _GetFriendlyName($oInterface, $PnPDeviceID)
    Local $sString = ""
    Local Const $Size = 128
    $oInterface.GetDeviceFriendlyName($PnPDeviceID, $sString, 128)
    Return $sString
EndFunc   ;==>_GetFriendlyName

Func _GetProperty($oInterface, $PnPDeviceID)
    Local $sString = ""
    Local Const $Size = 128
    $oInterface.GetDeviceFriendlyName($PnPDeviceID, $sString, 128)
    Return $sString
EndFunc   ;==>_GetProperty

Func FAILED($hr)
    Return ($hr < 0)
EndFunc   ;==>FAILED

 

Saludos

4 people like this

Share this post


Link to post
Share on other sites



#2 ·  Posted

I know it's more than 2 years later and I hope my question is not to stupid.

Is there a way to enumerate the WPD Device Properties for the devices returned by this script? I don't know enough programming to explain this properly but I would be interested in the properties listed at https://msdn.microsoft.com/en-us/library/windows/hardware/ff597865(v=vs.85).aspx for each portable device returned by this script. I would be interested in WPD_DEVICE_FIRMWARE_VERSION and WPD_DEVICE_MODEL besides other properties. I can see my phones and tablets but I can't even get started to get from here (get the phone) to there (get the firmware version).

Any hint would be appreciated.

Share this post


Link to post
Share on other sites

Here you can find some more info on this ...

https://www.pdq.com/blog/where-can-i-find-a-device-s-firmware-version-in-wmi/ 

#RequireAdmin

Func GetFirmware() ;$id
Local $FirmWare, $strComputer = "."


Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$objFirmWare = $objWMIService.ExecQuery ("“SELECT * FROM MSDeviceUI_FirmwareRevision")

For $objItem In $objFirmWare
    ConsoleWrite("Active:" & $objItem.Active & @CRLF)
    ConsoleWrite("FirmwareRevision:" & $objItem.FirmwareRevision & @CRLF)
    ConsoleWrite("InstanceName:" & $objItem.InstanceName & @CRLF)
Next

EndFunc

But you need some extra tool : DevCON in conjunction with this script.

Not tested it tough just translated it for your purpose...

Rgds

ptrex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hi all
      I want a way to get the last key pressed.
      I have a program that works with keyboard shortcuts and I want to  give the permission for the user to edit shortcut keys depending on what suits him
      i  want to make read-only edit box and the program writes the latest shortcut key pressed
      Please help me,
      greetings to all
      And thanks in advance
    • nacerbaaziz
      By nacerbaaziz
      hello guys
      how are you؟
      I hope to be fine.
      I have a question  please
      how do I get the menu item that was pressed without that contains a variable؟
      For example I have a menu  of Favorites and I want the script recognizes the existing path in the pressed item
      i'll repeat to tell the item does not contain a variable
      Is there any solution
      if you want to explain more I could write an example of what I want.
      Greetings to all,
      thanks in advance
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an urgent question, please help.
      How do I select all the text in the edit or input
      And how to get the currently selected text
      Please help urgently
      Greetings and thanks for all
    • WoodGrain
      By WoodGrain
      Hi All,
      I've coded the small script below, but it can't seem to get the instance of Windows Media player as it keeps going to @error, I've not used com objects before so any assistance would be appreciate. I already have WMP open and minimised. I retrieved "WMPlayerApp" from the AutoIT info tool, I've included a copy below.
      I'm using these sources:
      https://msdn.microsoft.com/en-us/library/dd564085.aspx
      https://msdn.microsoft.com/en-us/library/dd564018.aspx
      $oWMP = ObjGet("", "WMPlayerApp") If @error Then MsgBox(0, "Can't get WMP", "Couldn't connect to the WMP instance") Exit EndIf $wmpPlayState = $oWMP.playState MsgBox(0, "Play State", $wmpPlayState) $wmpSongName = $oWMP.currentMedia.name MsgBox(0, "Play State", $wmpSongName) I've also seen references to the below, but I want to get an existing open WMP:
      ObjCreate("wmplayer.OCX") and have looked at the WMP.udf but can't see how it will do either of the functions I've coded above.
       
    • Miliardsto
      By Miliardsto
      Hello i have problem with function PixelGetColor. On my computer it working fine but in some cases it not working.
      And Im clicking on the active window on red color and it give me the same color still. But in other computers when clicking on the same color red it gives other values and returned color in MsgBox is not red.
      Dont know is it a real main thing what causing problem but,
      I noticed that problem was on one windows 10.
      I have windows 8 and working well. On other windows 10 works well to
      Maybe it is caused by windows aero or something like that
      How to deal with it?
      There is a code
      HotKeySet("{PAUSE}", "MouseCord") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func MouseCord() Global $MousePos = MouseGetPos() $clickedColor = PixelGetColor($MousePos[0], $MousePos[1]) MsgBox(0, "Done", $clickedColor) EndFunc