I’m going through some old scripts I’ve written or stolen from my years as a solutions engineer / developer and have come across one I thought was worthy of sharing.
The intent of this script was to loop through a list of USB devices found on a given PC.
I might store the results in a database as part of an device tracking inventory system or use the data to do something else in the code logic if I had found a specific USB device attached.
Example: VBScript to List all USB Devices
'http://blogs.technet.com/b/heyscriptingguy/archive/2005/03/15/how-can-i-determine-which-usb-devices-are-connected-to-a-computer.aspx
'Win32_PnPEntity info here: http://msdn.microsoft.com/en-us/library/aa394353(v=vs.85).aspx
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDevices = objWMIService.ExecQuery _
("Select * From Win32_USBControllerDevice")
For Each objDevice in colDevices
strDeviceName = objDevice.Dependent
strQuotes = Chr(34)
strDeviceName = Replace(strDeviceName, strQuotes, "")
arrDeviceNames = Split(strDeviceName, "=")
strDeviceName = arrDeviceNames(1)
Set colUSBDevices = objWMIService.ExecQuery _
("Select * From Win32_PnPEntity Where DeviceID = '" & strDeviceName & "'")
For Each objUSBDevice in colUSBDevices
Wscript.Echo objUSBDevice.Description & ": " & objUSBDevice.Manufacturer
Next
Next
If you run this script on a remote computer on a network domain instead of your own, you will probably have to run this script with Administrator rights depending on the who the network is configured.
You can check out my article on how to run VBScript as an administrator if you need help with that.
Hope this helps somebody! 🙂
~Cyber Abyss