I've taken this code from a VB App that I'm writing.
Code:
Public Function EnumCommPorts(Port As Integer) As Boolean
Dim comCfg As COMMCONFIG, comSize As Long
comSize = LenB(comCfg)
EnumCommPorts = IIf(GetDefaultCommConfig(("COM" & Trim(Str(Port)) & vbNullChar), comCfg, comSize), True, False)
End Function
All you need to is create a loop and pass it an integer starting at 1 going (if needed) to 16. If it returns true then the port is present on the system. Sorted.
You'll need to tweak it to suit, but it does work.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.