Force assign COM ports using command line.

Discussion in 'General Discussion' started by Fugazi, Apr 20, 2017.

  1. Fugazi

    Fugazi

    Joined:
    Jan 23, 2017
    Messages:
    5
    Likes Received:
    0
    Hi, please move if this is in the wrong place.

    I need to force Windows 10 to accept two USB devices on specific COM Ports and have come up blank on how to do this via Command Line.

    I can clear all 'hidden' devices to ensure the required COM Ports are free using the following code -

    Code (Text):
    @ECHO OFF
    FOR %%i IN (C D E F G H I J K) DO IF EXIST %%i:\remove.cmd SET Drive=%%i:
    %DRIVE%\DEVCON Find * | FIND /I /V "matching device(s)" > "%DRIVE%\DevicesExist.txt"

    FOR /F "tokens=1 delims=: " %%A IN ('%DRIVE%\DEVCON FindAll * ^| FIND /I /V "%DRIVE%\matching device(s)"') DO (
            TYPE "%DRIVE%\DevicesExist.txt" | FIND "%%~A" >NUL
           IF ERRORLEVEL 1 %Debug% %DRIVE%\DEVCON Remove "@%%~A"
    )
    Del "%DRIVE%\DevicesExist.txt"
    But when I plug in the two Devices I need to assign them to COM Port 4 & 5 respectfully .. does anyone have any idea how to go about this .. I understand it will require adjusting registry entries.

    TIA for any help
     
    Fugazi, Apr 20, 2017
    #1
    1. Advertisements

  2. Fugazi

    Regedit32 Moderator

    Joined:
    Mar 4, 2016
    Messages:
    2,762
    Likes Received:
    833
    Can you not more simply:
    • Open Device Manager
    • Expand Ports (COM & LPT)
    • Right-click on the device you want to change com port on, and select Properties
    • Select the Port Settings tab
    • Click the Advanced button
    • Select the Com you want and click OK
    Note: the device needs to plugged in and turned on to be detected in Device Manager in order to change com ports.​
     
    Regedit32, Apr 20, 2017
    #2
    Trouble likes this.
    1. Advertisements

  3. Fugazi

    Fugazi

    Joined:
    Jan 23, 2017
    Messages:
    5
    Likes Received:
    0
    Yes I could .. but I need to do it using Command line programming.
     
    Fugazi, Apr 24, 2017
    #3
  4. Fugazi

    Regedit32 Moderator

    Joined:
    Mar 4, 2016
    Messages:
    2,762
    Likes Received:
    833
    Well you could take a look at the DEVCON information page produced by Microsoft:

    https://msdn.microsoft.com/en-us/windows/hardware/drivers/devtest/devcon-restart

    There may be some useful information there.

    In earlier editions of Windows there was the change portX = portY command, but the problem with that is it only assigns the port while User is logged on, thus you'd have to do this each time you wished to used your device.

    To be honest I'm not even sure whether that very old MS-Dos is even supported now.

    So it seems you will need to download support packages as you apparently already have done re the DEVCON
     
    Regedit32, Apr 24, 2017
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.