|
-
Jul 5th, 2003, 06:02 AM
#1
Thread Starter
Lively Member
Retrieving the numbers of comports
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
Best Regards from.
Chris101
-
Jul 5th, 2003, 06:57 AM
#2
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!
-
Jul 5th, 2003, 10:14 AM
#3
Thread Starter
Lively Member
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
Best Regards from.
Chris101
-
Jul 9th, 2003, 07:48 AM
#4
Addicted Member
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..
-
Jul 11th, 2003, 03:53 AM
#5
Thread Starter
Lively Member
Hi Dazzer.
This is exactly what I was looking for, do you know if this also will work on XP ??.
Best regards from.
Chris101
-
Jul 11th, 2003, 06:52 AM
#6
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|