Switching COM Ports using script or Powershell or command line

AKR2021 1 Reputation point
2021-08-17T16:24:20.807+00:00

Hello,

I am working on OEM. I use a windows image to install the devices. When the device is newly installed , the COM ports are shifted to 9-16 rather than 1-8 and it shows as comports 1-8 are in use. Is there a possibility to write a script to change the COM Port numbers. I was changing them manually till now but manual changes is not an option any more.

Thank you

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,518 questions
Windows 10 Compatibility
Windows 10 Compatibility
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Compatibility: The extent to which hardware or software adheres to an accepted standard.
456 questions
Windows 10 Setup
Windows 10 Setup
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Setup: The procedures involved in preparing a software program or application to operate within a computer or mobile device.
1,908 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,831 Reputation points
    2021-08-18T10:57:54.033+00:00

    It can be done in C++, but it is complex, because there are several steps :
    DefineDosDevice
    Writing to
    HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM with RegSetValueEx
    ComDBReleasePort
    ComDBClaimPort
    SetupDiSetDeviceRegistryProperty with SPDRP_FRIENDLYNAME
    SetupDiSetDeviceInstallParams with DI_PROPERTIES_CHANGE

    1 person found this answer helpful.
    0 comments No comments