Link to home
Start Free TrialLog in
Avatar of alexandram
alexandram

asked on

List available COM ports

I have a screen from which users select a COM port. Instead of just listing COM1... COM8 in a listbox, I would like to display available com ports only.
Avatar of dwwang
dwwang

below is in the MSDN article "Serial Communications in Win32":

                   One thing to note about port names is that traditionally they have
                   been COM1, COM2, COM3, or COM4. The Win32 API does not provide any
                   mechanism for determining what ports exist on a system. Windows NT and
                   Windows 95 keep track of installed ports differently from one another,
                   so any one method would not be portable across all Win32 platforms.
                   Some systems even have more ports than the traditional maximum of
                   four. Hardware vendors and serial-device-driver writers are free to
                   name the ports anything they like. For this reason, it is best that
                   users have the ability to specify the port name they want to use. If a
                   port does not exist, an error will occur (ERROR_FILE_NOT_FOUND) after
                   attempting to open the port, and the user should be notified that the
                   port isn't available.

So that you should enumerate them by checking the registry:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\Ports, or
HKEY_LOCAL_MACHINE\Hardware\devicemap\serialcomm

However, in Win95/NT, the location might be slightly different.
Avatar of alexandram

ASKER

Thank you. I guess I won't bother since my application runs on both 95 and NT.
ASKER CERTIFIED SOLUTION
Avatar of ronit051397
ronit051397

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.