forked from todbot/usbSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listComPorts.vbs
52 lines (47 loc) · 1.55 KB
/
listComPorts.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
'
' listComPorts -- List all COM, even USB-to-serial-based onesports,
' along with other info about them
'
' Execute on the command line with:
' cscript.exe //nologo listComPorts.vbs
'
' http://github.com/todbot/usbSearch
'
' 2012, Tod E. Kurt, http://todbot.com/blog/
'
' core idea stolen from
' http://collectns.blogspot.com/2011/11/vbscript-for-detecting-usb-serial-com.html
' And this is fun, if not particularly useful:
' http://henryranch.net/software/jwmi-query-windows-wmi-from-java/
'
Set portList = GetComPorts()
portnames = portList.Keys
for each pname in portnames
Set portinfo = portList.item(pname)
wscript.echo pname & " - " & _
portinfo.Manufacturer & " - " & _
portinfo.PNPDeviceID & _
""
'portinfo.Name & " - " & _
Next
'
' For all the keys in an entity, see
'http://msdn.microsoft.com/en-us/library/windows/desktop/aa394353(v=vs.85).aspx
'
Function GetComPorts()
set portList = CreateObject("Scripting.Dictionary")
strComputer = "."
set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colItems = objWMIService.ExecQuery _
("Select * from Win32_PnPEntity")
for each objItem in colItems
set objRgx = CreateObject("vbScript.RegExp")
strDevName = objItem.Name
objRgx.Pattern = "COM[0-9]+"
set objRegMatches = objRgx.Execute(strDevName)
if objRegMatches.Count = 1 then
portList.Add objRegMatches.Item(0).Value, objItem
end if
Next
set GetComPorts = portList
End Function