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 device, Windows creates a new virtual COM port with a value from 1 to 255. When you remove this device, the created COM port will not be deleted automatically. And any new COM port is assigned the first unallocated COM port number.
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 CommDB registry key under 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 or devcon utility.
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 \Windows\system32 in the Command Prompt and then press Enter.
Type start devmgmt.msc in the Command Prompt and then press Enter.
Check if the hidden devices are connected to PC.
Click View > Show hidden devices. This will display devices that are not connected to your computer.
Step 6: Uninstall COM ports in use
Now if you expand the section on COM ports, all the COM ports that have ever been created will be displayed (the non-present ones being in grey). You can uninstall away anything that you don’t want (right click, select Uninstall).
Also, you can clean up garbage COM ports by using the DevCon utility that is included to 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 busy 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\3&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 port reassignment
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.