vikashbitm2010 Posted November 11, 2016 Share Posted November 11, 2016 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 ? Link to comment Share on other sites More sharing options...
4gotn1 Posted November 11, 2016 Share Posted November 11, 2016 An example to extract any USB's label (name). #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Local $arDrives = DriveGetDrive("ALL"), $USB = Null For $i = 1 to $arDrives[0] If (DriveGetType($arDrives[$i], $DT_BUSTYPE) = "USB") Then $USB = DriveGetLabel($arDrives[$i]) MsgBox($MB_OK, "USB", "Drive: " & $arDrives[$i] & @CRLF & "Label: " & $USB) EndIf Next Link to comment Share on other sites More sharing options...
JohnOne Posted November 11, 2016 Share Posted November 11, 2016 what if the usb device is not a drive? vikashbitm2010 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
vikashbitm2010 Posted November 11, 2016 Author Share Posted November 11, 2016 I want to have the hardware name which is conneted via USB. Please refer snapshot which I attached. My requirement is not to get the drive name. Link to comment Share on other sites More sharing options...
j0kky Posted November 11, 2016 Share Posted November 11, 2016 (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 November 11, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs Link to comment Share on other sites More sharing options...
4gotn1 Posted November 12, 2016 Share Posted November 12, 2016 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now