A
A
Alexander Shpak2015-08-23 05:41:41
API
Alexander Shpak, 2015-08-23 05:41:41

How to get a list of COM ports in Windows correctly?

It became curious how to get the list of serial ports in Windows correctly .
From the Internet, we managed to find out that there are a handful of ways and one is worse than the other. Let me explain that only a list of ports is needed, without any descriptions.
upd: I tend to read ports from the registry because they write this on msdn.microsoft:

Use the GetPortNames method to query for a list of valid serial port names on the current computer. For example, this method allows you to determine if COM1 and COM2 are valid serial ports for the current computer.
The port names are loaded from the system registry (for example, HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM). If the data in the registry is inaccurate or out of date, the GetPortNames method will return incorrect results.

upd2: Second priority method is WMI query

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2015-08-23
@gbg

The most reliable way, which not only finds ports, but also determines their employment, is a direct enumeration of all 255 name options.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question