-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathusbSearch.vbs
86 lines (73 loc) · 2.49 KB
/
usbSearch.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'
' usbSearch.vbs -- Find USB devices by VID & PID
' 2012, Tod E. Kurt, http://todbot.com/
'
' Execute on the command line with:
' cscript.exe //nologo usbSearch.vbs /VID:<vid> /PID:<pid>
' See usage() for more options
'
' references:
' http://blogs.msdn.com/b/powershell/archive/2007/02/24/displaying-usb-devices-using-wmi.aspx
' http://technet.microsoft.com/en-us/library/ee156618.aspx
'
'
' Some notable VID/PID combos:
' - Arduino Diecimila - VID:0403 PID:6001
'
'
sub usage()
wscript.echo "usage: usbsearch.vbs [help] [all]"
wscript.echo " usbsearch.vbs [quiet] [serial] /VID:<vid> [/PID:<pid>] "
wscript.quit
end sub
strUSBsearch = ""
quiet = 0
serial = 0
for each str in wscript.arguments.unnamed
if str = "all" or str = "/all" then strUSBsearch = "USB"
if str = "help" or str = "/h" then usage() ' why "/h" not work?
if str = "quiet" then quiet = 1
if str = "serial" then serial = 1
next
set namedArgs = wscript.arguments.named
strUSBVID = UCase(namedArgs.item("VID"))
strUSBPID = UCase(namedArgs.item("PID"))
if strUSBsearch = "" and strUSBVID = "" and strUSBPID = "" then usage()
' set up search string
if strUSBsearch = "" then
if strUSBVID <> "" then
strUSBsearch = "USB\VID_" & strUSBVID
if strUSBPID <> "" then
strUSBsearch = strUSBsearch & "&PID_" & strUSBPID
end if
end if
end if
if quiet = 0 then wscript.echo "Searching for " & strUSBsearch
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
if InStr( objUSBDevice.PnPDeviceId, strUSBsearch ) <> 0 then
if serial = 1 then
end if
if quiet = 0 then
wscript.echo objUSBDevice.PnPDeviceID & " - " & _
objUSBDevice.Description
else
wscript.echo objUSBDevice.PnPDeviceID
end if
end if
next
next
' Changed from Description to PnPDeviceID as this script can be altered
' to return any property of the Win32_USBControllerDevice collection.