78

How would I go about viewing a list of COM ports in use without the use of Device Manager?

I don't want to install any software either. Is there a possible way to do this through the command line?

5
  • Please better define "In Use". installed as a device? Has a device attached to it? Is actively transferring data? Nov 4, 2014 at 16:33
  • @Ƭᴇcʜιᴇ007 sorry, in use would be having a device attached to it. I have a ttl uart cable plugged into a USB.
    – Marmstrong
    Nov 4, 2014 at 16:36
  • I suppose you can do this through a powershell script. Why can't you use device manager? Your unwillingness to use something like Putty is odd.
    – Ramhound
    Nov 4, 2014 at 16:48
  • 1
    @Ramhound Using a University PC which has the device manager locked down to stop people like me fiddling. I can see that the device is COM3 on my laptop. I want to use Putty but I don't know which COM port to use.
    – Marmstrong
    Nov 4, 2014 at 16:50
  • 2
    @Marmstrong In the command prompt use mode. Used without parameters, mode displays all the controllable attributes of the CON (console) and the available COM devices (and LPT as well)
    – JosefZ
    Nov 5, 2014 at 0:51

7 Answers 7

93

In the command prompt use

mode

Used without parameters, mode displays all the controllable attributes of the CON (console) and the available COM devices (and LPT as well).

Accepts /? switch for basic help:

mode /?

2
  • 3
    Using mode most of the time I don't see the devices that are not connected, as mentioned in @G-M 's answer.
    – sylvainulg
    Mar 6, 2019 at 14:14
  • mode is for configuring system devices. This does work... until I connect something like Putty to the COM port. Which I guess makes sense, it the port is not configurable while in use. A better "query only" method is in @lithiumhead's answer. Dec 9, 2021 at 17:12
29

I know the question has been answered, but this is another method.

In command prompt, use:
chgport
in windows Vista and up. Lists your ports and which device they are.

8
19

In the command prompt use:

C:\>wmic path Win32_SerialPort

In PowerShell, run as administrator:

PS> Get-WMIObject Win32_SerialPort | Select-Object Name,DeviceID,Description

Or, for raw data:

PS> Get-WMIObject Win32_SerialPort

Hope this helps.

6
  • 6
    The command prompt returned No Instance(s) Available.
    – Marmstrong
    Nov 4, 2014 at 16:46
  • If there are no Com port devices detect then the command results "No Instance(s) Available". Check your "Device Manager" and ensure your machine detected the Com ports in "Device Manager"
    – BDRSuite
    Nov 4, 2014 at 16:53
  • OP said "Using a University PC which has the device manager locked down"
    – DavidPostill
    Nov 4, 2014 at 16:54
  • @vembutech - Looks like you will need to get IT involved in that case.
    – Ramhound
    Nov 4, 2014 at 16:56
  • @vembutech I have checked the device on my own laptop and it appears as COM3 in device manager but the command prompt still shows the same result.
    – Marmstrong
    Nov 4, 2014 at 16:56
14

You can also run the following from cmd.exe prompt

reg query HKLM\HARDWARE\DEVICEMAP\SERIALCOMM

And here is an open source utility to do the same and more: https://todbot.com/blog/2012/03/02/listcomports-windows-command-line-tool-for-usb-to-serial/

1
  • Thanks! This actually worked.
    – Mooncrater
    Sep 2, 2020 at 5:50
8

Using mode most of the time I don't see the devices that are not connected.

I prefer to use this solution with Python:

python -c "import serial.tools.list_ports as ls; print([p.device for p in ls.comports()])"

So I can see anything plugged in even if the connection is closed.

serial.tools.list_ports is from package pyserial.

2
  • idk when this worked, but now the __repr__ of the objects has changed and I get [<serial.tools.list_ports_common.ListPortInfo object at 0x00000000036ECCC8>, <serial.tools.list_ports_common.ListPortInfo object at 0x00000000036ECD88>]
    – Jason S
    Dec 10, 2020 at 19:13
  • 1
    looks like you need the description or device properties now: python -c "import serial.tools.list_ports as ls;print [p.device for p in ls.comports()]"
    – Jason S
    Dec 10, 2020 at 19:16
7

wmic https://docs.microsoft.com/en-us/windows/desktop/wmisdk/wmic is a windows command line utility to get system information.

If your serial port is virtual created by some driver through USB connection, use this example to get details about these serial ports.

wmic path CIM_LogicalDevice where "Description like 'USB Serial%'" get /value
2
  • a bit of further information would be helpfull
    – Albin
    Nov 16, 2018 at 17:55
  • that produces lots of information. get Name instead of get /value might help. Unfortunately, it won't simply list ports, but strings such as "USB Serial Port (COM17)". There are also multiple entries mentioning simply "USB Serial Converter" on my setup.
    – sylvainulg
    Mar 6, 2019 at 14:22
1

The snippet below lists serial ports into the $PORTS variable

# BASH MSYS2
# This function will get a list of ports automatically
PORTS=`/c/Windows/System32/mode.com | grep Status.*COM | awk '{ print $4 }' | sed s/://`

# To the list (use) the ports, see the code below:

echo -n "Programming (echoing) ports: "
for aa in $PORTS; do
    echo -n $aa
done
echo ""
1
  • What I like about this answer is that I can use it within a bash script. Oct 9, 2020 at 21:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .