Jump to content

Recommended Posts

Posted

Hello,

Once i connect the hardware through USB, its appearing in the device manager(Refer snapshot attached) -

Hardware name: CANCASEXL

I want to get the name of the hardware. Is it possible to get through AutoIt ?

deviceMGR.PNG

Posted (edited)

This is an old script (mine? I don't know) which retrieves the letter of an inserted volume, I think you can convert it to volume name with _WinAPI_QueryDosDevice (but I'm not sure it is the right function):

Global Const $WM_DEVICECHANGE = 0x0219, $DBT_DEVICEARRIVAL = 0x8000, $DBT_DEVTYP_VOLUME = 0x00000002
$hWndGUI = GUICreate("GUI")
GUISetState(@SW_HIDE)
GUIRegisterMsg($WM_DEVICECHANGE, "WM_DEVICECHANGE")

While 1
    Sleep(1000)
WEnd

Func WM_DEVICECHANGE($hWndGUI, $MsgID, $WParam, $LParam)
    If $WParam = $DBT_DEVICEARRIVAL Then
        $s_DEV_BROADCAST_HDR = DllStructCreate("DWORD;DWORD;DWORD", $LParam)
        If DllStructGetData($s_DEV_BROADCAST_HDR, 2) = $DBT_DEVTYP_VOLUME Then
            $s_DEV_BROADCAST_VOLUME = DllStructCreate("DWORD;DWORD;DWORD;DWORD;WORD", $LParam)
            If DllStructGetData($s_DEV_BROADCAST_VOLUME, 5) = 0 Then
                $dbcv_unitmask = DllStructGetData($s_DEV_BROADCAST_VOLUME, 4)
                Return _DriveLetter($dbcv_unitmask)
            EndIf
        EndIf
    EndIf
EndFunc

Func _DriveLetter($dbcv_unitmask)
    Local $AZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", $letter, $counter = 1
    While $dbcv_unitmask > 1
        $dbcv_unitmask /= 2
        $counter += 1
    WEnd
    If $counter <= StringLen($AZ) Then
        $letter = StringMid($AZ, $counter, 1)
    Else
        $letter = "?"
    EndIf
    Return $letter
EndFunc

 

Edited by j0kky
Posted
On 11/11/2016 at 3:23 AM, JohnOne said:

what if the usb device is not a drive?

I misread OP, or just assumed when reading "USB" they were referring to a thumb drive =\ Apologies. 

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...