12

Does anybody know how to change the COM port number that Windows maps to a USB virtual COM port? You can change this via the Device Manager and clicking on the Advanced button.. but how can you do this via an API, registry change or command line operation?

Any ideas please?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
SparkyNZ
  • 6,266
  • 7
  • 39
  • 80

4 Answers4

8

I monitored registry changes during changing COM port 1 to 110 and found modifications in following keys:

[HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM] "\Device\Serial0"="COM110"

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\COM Name Arbiter] "ComDB"=hex(3):FC,7F,00,00,00,00,00,00,00,00,00,00,00,20,00,00,00,00,00,00,\ 00,00,00,00,00,00,00,00,00,00,00,00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\ACPI\PNP0501\1\Device Parameters] "PortName"="COM110"

Alireza
  • 81
  • 1
  • 3
  • I didn't even know one could do that! I found a handy Microsoft tool that does the job at the following link: https://learn.microsoft.com/en-us/sysinternals/downloads/procmon – DatuPuti Dec 13 '18 at 06:29
  • You can also use https://www.nirsoft.net/utils/registry_changes_view.html to easly watch reg changes like this. – Johan A. Mar 29 '19 at 08:56
7

You might find this answer useful:

How do I get the friendly name of a COM port in Windows?

It's about finding the friendly name, but I think you'll find it points you towards the right area of the registry, using the 'official' mechanism for locating the right key.

However, if you change the port assignment, you should also update the com port database - see: https://msdn.microsoft.com/en-us/library/ff546481.aspx

When I had to do something similar, I found the right device using the mechanism described in the linked SO article, and then called SerialDisplayAdvancedSettings((HWND)NULL, hDeviceInfo, &devInfoData); to display the advanced dialog and let the OS handle the hard work.

Nowadays you're more and more likely to be encountering odd 'not real' serial ports (e.g. USB ports) which might have other incompatibilities you need to be wary of too.

Community
  • 1
  • 1
Will Dean
  • 39,055
  • 11
  • 90
  • 118
  • Thanks for this. Luckily the problem we have relates to an identical set of equipment and we only need a solution for this one type of PC. My collegue tried changing the registry as suggested below and we've managed to get it to work. I will be keeping your response safe though as it provides invaluable info for future use. Thanks to everybody who responded to this question. – SparkyNZ Jan 05 '10 at 01:47
  • For C#, I have added a sample code here in this way. https://www.pinvoke.net/default.aspx/msports/SerialDisplayAdvancedSettings.html – cactuaroid Feb 23 '20 at 13:20
5

This changing is done in two below steps in the registry through the "regedit":

  1. Change the name: In the first step, you need to change the below keys:

    1. In the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\XXX that XXX is your device name. You need to trace each item to find the FriendlyName and then change it as you wish (Ex: "USB Serial Port (6)");
    2. In the previous key, again you need to trace the item to find the PortName and change it to the port number (Ex: "COM6").
  2. Change the port number:

    1. In the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter, you can find the ComDB which is a bit mask of COM ports already allocated. This value should be change based on your COM ports. Note, The first byte controls COM8~1, the second byte controls COM16~9, the third byte controls COM24~COM17 and so on. A value=0 means that the port is not used. A value=1 means that the port is occupied.
Farzad
  • 279
  • 4
  • 5
  • 1
    I also had to edit `HKLM\SYSTEM\CurrentControlSet\Enum\XXX\FriendlyName` to show the correct COM port as well. Otherwise that won't match what it's actually set to. – 4oo4 Jan 07 '20 at 21:33
1

Offhand, I don't know how to do it, but here's what I would do:

Use the My Computer/ Device Manager method to assign some unlikely com port, like 61. Then use regedit to search for COM61 and see what Device Manager did.

I know I've seen all these things in the registry somewhere, but a quick search of the knowledge base didn't turn up the answers.

wallyk
  • 56,922
  • 16
  • 83
  • 148