How can I remove all COM ports from the command line on Windows 7?

4

2

We have a computer that's used to test some devices. Every once in a while, testers need to go in and remove the assigned COM ports so they free up and start back at 1. Lately, it's been assigning them the same COM port to a couple of devices (around 8 are connected at the same time) and also, they need to change the test code to match whatever number was assigned by the OS.

Duplicate numbers was the reported problem, but I see the 'having to check the COM ports and updating the code' multiple times a day as a problem too.

In Device Manager, if I turn on to show hidden devices, I see hundreds of them!

Enter image description here

You can tell by the size of the scrollbar the list is pretty big. I can click at each one and uninstall, but that's insane going 1 by 1 which is why I ask for a command-line alternative, so I can write a script that they can double click when they need to reset the ports.

Of course, if there's some software out there that will allow for this to happen then that's good too.

geermc4

Posted 2013-02-06T21:13:17.397

Reputation: 143

Answers

6

Remove active USB ports:

devcon /r remove @usb\*

Remove active LPT and COM ports:

devcon /r remove =ports

Query all COM and LPT ports:

devcon FindAll =Ports

Query active USB ports:

devcon status @usb\*

Query all USB ports - different results:

devcon findall @usb\*
devcon findall =USB

Enum all devices:

devcon hwids * > hwids.txt

Part at WDK, Windows Driver Kit Version 7.1.0.

The old version, 2003-01-29, does not work on Windows 7 (not del device). devcon old version 2003-01-29

Source code for DevCon

Alternative 1 - PnPUtil

Alternative 2 - registry key, search USB device at subkey

Not del all!

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\ACPI

Example:

reg delete "HKLM\SYSTEM\CurrentControlSet\Enum\USBSTOR\Disk&Ven_Seagate&Prod_USB_2.0_Cable&Rev_0148" /f

If ports enumerate devcon FindAll =Ports - delete this registry key:|

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\ACPI

If ports enumerate devcon status @usb\* - delete this registry key:|

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB

Example:

Open registry

Change permission

Delete key

Thx geermc4! I tested devcon. On Windows Driver Kit Version it works correctly with Windows 7.

The hardware profile can be set up only for Windows XP. We will not be able to setup on Windows 7. It is by design ... backup HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum ...

STTR

Posted 2013-02-06T21:13:17.397

Reputation: 6 180

that place you suggested in the registry does look like the place, but devcon seems more straight forward, I do see a long list of devices with devcon, but when i try the remove command i get 'Remove Failed' on all – geermc4 – 2013-02-07T00:29:52.907

@geermc4 port enumerate devcon FindAll =Ports or devcon status @usb\* ? – STTR – 2013-02-07T00:32:26.457

2those did work, just remove failed, I was trying with the old version link since it is a single smaller file to download, but now trying with the new version and that is working yay! – geermc4 – 2013-02-07T00:43:10.673

1@geermc4 Thx at good comment! Good Luck! – STTR – 2013-02-07T01:33:11.797

-1

I also need to test hundreds of units. However I tried to use command line " devcon /r remove @usb*" and devcon /r remove =ports", which did not work. I also download WDK (donot know how to use it). I felt confused after reading the conversation. @geermc4 and @STTR, would you explain again how you did it?

Albert4913

Posted 2013-02-06T21:13:17.397

Reputation: 1

This does not really answer the author's question, due to the clarification request, answer should only be used to answer a question. – Ramhound – 2017-02-08T21:38:47.253

This is not an answer to the original question. If you have a new question please ask your own question (referencing this one for context if it helps).

– DavidPostill – 2017-02-09T10:41:44.187