Permalink
Browse files

finally a way to list comports, tho hacky

  • Loading branch information...
todbot committed Mar 1, 2012
1 parent d0f9847 commit 69438422d724859a8b0de2383638dac66fbdba90
Showing with 48 additions and 0 deletions.
  1. +48 −0 listComPorts.vbs
View
@@ -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.