Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to enumerate comm ports?

321 views
Skip to first unread message

Paul D. DeRocco

unread,
Jul 4, 2009, 12:29:18 AM7/4/09
to

In a Win32 or .NET app, how do I find a list of all existing comm ports,
including those currently in use? Trying to open COM1, COM2, COM3, etc.
fails on ports that are in use. The Device Manager is able to do this, but I
can't find the API for enumerating these devices.

--

Ciao, Paul D. DeRocco
Paul mailto:pder...@ix.netcom.com


JJ

unread,
Jul 4, 2009, 2:09:37 AM7/4/09
to

Paul D. DeRocco wrote:
> In a Win32 or .NET app, how do I find a list of all existing comm ports,
> including those currently in use? Trying to open COM1, COM2, COM3, etc.
> fails on ports that are in use. The Device Manager is able to do this, but I
> can't find the API for enumerating these devices.

You can use QueryDosDevice to retrieve the device paths for each COMn
ports as well as LPTn ports. Check it one at a time. For COM ports,
there can be up to 256 ports (COM1 to COM256). Each can be in any COM
port number, so three COM ports can be COM4, COM11 and COM200.

Maxim S. Shatskih

unread,
Jul 4, 2009, 6:56:22 AM7/4/09
to

SetupDiGetClassDevs for GUID_DEVINTERFACE_COMPORT.

Then use the names got from SetupDiGetDeviceInterfaceDetail, instead of the ancient-style COM%d names. You can also get the human-readable description for each port, which IIRC contains the sacred "COM1" string.

--
Maxim S. Shatskih
Windows DDK MVP
ma...@storagecraft.com
http://www.storagecraft.com

"Paul D. DeRocco" <pder...@ix.netcom.com> wrote in message news:O4OJBAG$JHA....@TK2MSFTNGP03.phx.gbl...

Paul D. DeRocco

unread,
Jul 6, 2009, 2:03:37 PM7/6/09
to
> "JJ" <jcu...@gmxNOSPAM.net> wrote

> You can use QueryDosDevice to retrieve the device paths for each COMn
> ports as well as LPTn ports. Check it one at a time. For COM ports, there
> can be up to 256 ports (COM1 to COM256). Each can be in any COM port
> number, so three COM ports can be COM4, COM11 and COM200.

That seems to do it, although I seem to have a mysterious permanent COM3
that isn't listed in Device Manager. But HyperTerminal sees it too, so I
guess it's some virtual device and not a bug. Thanks.

Doron Holan [MSFT]

unread,
Jul 6, 2009, 4:28:47 PM7/6/09
to

the SERIALCOMM key will also tell you about COM ports

--

This posting is provided "AS IS" with no warranties, and confers no rights.


"Paul D. DeRocco" <pder...@ix.netcom.com> wrote in message

news:eBpCZQm$JHA....@TK2MSFTNGP02.phx.gbl...

0 new messages