Skip to content

Commit

Permalink
finally a way to list comports, tho hacky
Browse files Browse the repository at this point in the history
  • Loading branch information
todbot committed Mar 1, 2012
1 parent d0f9847 commit 6943842
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions listComPorts.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'
' ListComPorts -- List all COM, even USB-to-serial-based onesports,
' along with other info about them
'
' 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 & _
""
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

0 comments on commit 6943842

Please sign in to comment.