Hi All.
Is there a way to retrieve the numbers of Comports there is on a PC in a windows environment ??.
Best regards from.
Chris101
Printable View
Hi All.
Is there a way to retrieve the numbers of Comports there is on a PC in a windows environment ??.
Best regards from.
Chris101
Yup! You can call on the EnumPorts API call. This will list all of the ports such as LPT printer ports, com ports etc on the local pc.
There's a sample over at www.allapi.net too! :)
Isn't there another way ?, this finds ALL the ports on the PC (not only the com ports) and more, by more i mean that it says that my PC has com1 - 4 but it has only com 1 - 2 in the real world.
Regards from.
Chris101
Ahh... the old QueryDosDevice Solution...
Copy this code into a blank Form
Code:Private Declare Function QueryDosDevice Lib "kernel32" Alias "QueryDosDeviceA" (ByVal lpDeviceName As String, ByVal lpTargetPath As String, ByVal ucchMax As Long) As Long
Sub Form_Load()
Dim lngCount As Long
Dim s As String
Dim Ret As Long
Dim PortCount As Long
For lngCount = 1 To 100
s = String$(255, Chr$(0))
Ret = QueryDosDevice("COM" & CStr(lngCount), s, Len(s))
s = Mid$(s, 1, InStr(s, Chr$(0)) - 1)
If s <> "" Then
Debug.Print "Found >COM" & cstr(lngCount)
PortCount = PortCount + 1
End If
Next
MsgBox("Found " & cstr(PortCount) & " Com Port(s)")
End Sub
You will notice that the Debug.Print tells you exactly what Ports are around...
Good Luck..
Hi Dazzer.
This is exactly what I was looking for, do you know if this also will work on XP ??.
Best regards from.
Chris101
Yes.