In case you are facing with trouble with your COM ports in use that stacking, these brief steps below will help you to clear them out (for example, when you found myself needing to connect via a USB to Serial adapter to a server and noticed that 35 COM ports showed in use). Somehow the COM ports were not getting cleared out.
The fact is that when you connect a new COM or a USB device (such as smartphone, modem, RS232 to USB converters, etc.), Windows detects newly connected device using Plug-and-Play (PnP) and creates a new virtual COM port with a number from 1 to 255. When you remove this device, the created COM port will not be deleted automatically. If you reconnect this device to a computer, the system re-assigned to it the reserved COM port number. But for any new COM device is assigned the first unallocated (free) COM port number. Thus, over time, a large number of reserved COM ports (in “in use” state) for certain COM or USB devices may appear in the system, although the devices themselves may not be connected to your computer. These ports by-default are not visible to the user in Device Manager.
Some legacy applications do not work correctly with COM ports with numbers 10 and higher. What to do in case your COM device received such a number? This time we will show you how to delete reserved COM ports and remap the COM port for a particular device.
Delete COM Port in Use
Information about the COM ports in use is stored in the registry parameter CommDB under the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter. However, changing the value of this attribute manually is rather risky. It is much easier to clear information about used COM ports using Device Manager, devcon CLI utility or COM Name Arbiter Setter tool.
Step 1: Run Command prompt
One thing is to see if hidden devices are taking up the ports: run Command Prompt (cmd.exe) with the elevated privileges.
Type set devmgr_show_nonpresent_devices=1 in the Command Prompt and then press Enter (you might have to restart your computer after this step).
Type cd c:\Windows\system32 in the Command Prompt and then press Enter.
Type start devmgmt.msc in the Command Prompt and then press Enter.
Activate the display of hidden devices from the top menu by clicking View > Show hidden devices. This will list all devices including those that are not connected to your computer.
Step 6: Uninstall COM ports in use
Now if you expand the Ports (Com&LPT) section, all the COM ports that have ever been created will be displayed (the hidden and unused ones being in grey). You can uninstall away anything that you don’t want (right click, select Uninstall).
This way you can delete all unused and hidden COM ports. Be careful and do not accidentally delete COM ports that work fine.
You can view a full list of assigned COM ports without Device Manager with the help of Command prompt commands:
wmic path Win32_SerialPort
or PowerShell cmdlet Get-WMIObject:
Get-WMIObject Win32_SerialPort | Select-Object Name,DeviceID,Description
Using DevCon to Delete Unused COM Ports
Also, you can clean up unused COM ports with the help of DevCon utility that is included in the Windows Driver Kit (WDK), Visual Studio and Windows SDK for desktop apps. Open the Command Prompt and go to the directory with the program:
List the reserved COM ports with the command:
devcon findall =ports
Now you can consistently remove all unused ports using their IDs, for example:
devcon remove @”PCI\VEN_8086&DEV_A13D&SUBSYS_30BE17AA&REV_31&11583659&0&B3”
Thus, you can delete all unnecessary COM ports (if you try to remove the used device, the Remove failed error appears).
COM Name Arbiter Setter Tool
Also, you can easily remove unused COM-Ports with the help of a graphical tool – COM Name Arbiter Setter V0.7 (you can download it here). This utility could help you to modify registry parameter ComDB in a simple way.
Download and extract the archive com_name_arbiter_setter.zip. Run COM_Name_Arbiter_Setter.exe with administrator permissions to allow access to system registry.
You can see on the screenshot that only COM1 and COM3 ports are reserved.
You can delete all COM port reservations by clicking Clear non present button, or by unchecking all unused COM ports. Click Apply to save changes and clear com ports assignment.
COM Port Re-assignment
If you need to reassign the COM port for a specific device:
- Open the Device Manager;
- In the Ports section, open the Properties of the device to which you want to reassign the COM port;
- Click the Port Settings tab, and then click the Advanced button;
- In the Com Port Number drop-down list, select the desired number and press OK.