Find USB-attached device(s)

Started by fhammer, December 22, 2016, 11:55:34 AM

Previous topic - Next topic

fhammer

Does anyone know a way to (within a WIL script) get a list of USB devices attached to the local system, or to search for a particular type of device?

Notes:

1) I was able to locate an attached USB modem by using serial extender function pComOpen, and looping through possible COM port ID's (COM1, COM2, ...) (with ERRORMODE temporarily OFF), but that involves a relatively-time-consuming exchange with the possible modem for each iteration).

2) I use a freeware utility called USBDEview (nirsoft) on my Windows 10 system to display the devices and types attached to my USB ports.

Russell_Williams

I have used the DiskScan function to get drives.

hd = DiskScan(2)
Message("Hard drives on system", hd)



td

DirScan(64) will give you a list of USB drives.  For a more general reckoning WMI is an options:

Code (winbatch) Select
strComputer = '.'

objWMIService = GetObject('winmgmts:\\':strComputer:'\root\cimv2')
colDevices = objWMIService.ExecQuery('Select * From Win32_USBControllerDevice')
ForEach objDevice in colDevices
   strDeviceName = objDevice.Dependent
   strDeviceName = StrReplace(strDeviceName, '"', '')
   strDeviceName = ItemExtract(2, strDeviceName, '=')

   colUSBDevices = objWMIService.ExecQuery(:"Select * From Win32_PnPEntity Where DeviceID = '":strDeviceName:"'")
   ForEach objUSBDevice in colUSBDevices
      if ObjectTypeGet(objUSBDevice) != 'EMPTY'
         Pause('Device Descript', objUSBDevice.Description)
      endif
   Next   
Next


Search on the WMI class names on MSFT's Website to find additional properties that might be of interest.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

fhammer

Thanks all. The DiskScan options only list drives. I will try the WMI option to get info on other types of USB-connected devices. WMI is new to me, so it may take a while. However, I'll reply back.