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?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityHow 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?
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 /?
mode
most of the time I don't see the devices that are not connected, as mentioned in @G-M 's answer.
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
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.
chgport
Applies To: Windows Server (Semi-Annual Channel), Windows Server 2016, Windows Server 2012 R2, Windows Server 2012.
Unable to get list of COM ports, error code = 0x5. No serial ports were found.
Windows 10 Enterprise, 20H2
Dec 9, 2021 at 17:12
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.
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/
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.
__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>]
description
or device
properties now: python -c "import serial.tools.list_ports as ls;print [p.device for p in ls.comports()]"
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
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.
Mar 6, 2019 at 14:22
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 ""
mode
. Used without parameters,mode
displays all the controllable attributes of theCON
(console) and the availableCOM
devices (andLPT
as well)