I've seen a few examples for this on the forums but none that correctly enumerated the ports on all my machines.
enum_ports.zip includes VB4-32 source code which does correctly enumerate all ports of all types (real and virtual) on my W98SE and XP systems. I no longer have a W2K machine so it has not been tested there.
It enumerates all the ports, filters out duplicates, infrared, etc. and adds all valid and available ports to a menu. (You could add them to a combo box instead.) It writes the current port to the registry and retrieves it at startup.
If you start it with the word ports on the command line it will output all of the RAW data to COMports.log. I've include a sample log from one of my older machines that has seen a lot of development work.
This was originally written for VB5 or VB6 and I had to modify it for VB4-32 so it should be fairly easy to get it running under VB5 or VB6. I think I had to find a way to convert the Unicode strings returned by the API. I believe later versions of VB had a function for this.
I've include a compiled example and the MSComm32.OCX control. You may need to register the OCX to run the example.
Enumerating COM ports
Enumerating COM ports
- Attachments
-
- enum_ports.zip
- VB4-32 source code for enumerating COM ports
- (60.1 KiB) Downloaded 4046 times