List Connected USB Device Name

Hello all,

How would one capture the name of a newly connected USB device in a listbox? I dont wish to read the contents but just list the name of the device.

This is my first time venturing into this area and have no clue on where to start.

If someone could point me in the right direction to get started, it would be greatly appreciated.

Best Regards

Robin.

MBS has a class for that - WinUSBDeviceMBS.

1 Like

There’s also this wonderful set of declares by Chris Carter that basically gives you everything DeviceManager gets

http://www.cmas-net.co.uk/rslug/Eg-5-DeviceList.rbp

Unfortunately it’s 32-bit only.

1 Like

WinUSBDeviceMBS class can do that.
Also check WindowsDeviceMBS class.

For Mac you can take a look on the MacUSBDeviceMBS class and the IORegistryMBS class.
For cross platform development also check LibUSBDeviceMBS classes.

There is a lot in MBS Xojo Plugins :slight_smile:

3 Likes

Thank you all kindly for the replies. I will check out the MBS plugins!

Robin

2 Likes

This may be of some use:

Public Function GetUSB() as String
  'Return a list of USB devices
  'Different command for each platform
  Dim My_Shell As New Shell
  My_Shell.TimeOut=-1
  #If TargetWindows Then
    'Windows
    My_Shell.Execute "cd\ & wmic path CIM_LogicalDevice where ""Description like 'USB%'"" get /value"
  #Elseif TargetMacOS 
    'Mac
    My_Shell.Execute "system_profiler SPUSBDataType"
  #Elseif TargetLinux
    'Linux
    My_Shell.Execute "lsusb"
  #Endif
  dim s As String = ReplaceLineEndings(My_Shell.Result,EndOfLine)
  return s
End Function

Parsing the returned string can be a bit messy, but I have some code for that somewhere, if needed.

2 Likes