Get COM port number of usb serial FTDI

I have a FTDI usb-serial and I am interested in the getting the COM port assigned to the device on USB serial converter A. Is there a way I can list this information programatically (say cmd) to extract the COM port number that corresponds to the one at that location. I can view this information in the device manager properties, so there could be a way to get this information through a script I guess? I am certain the COM port I would connect to will be on the serial converter A. I was looking up the registry entries for the usb device and the device I want to connect to goes to VCP0. to narrow down my question, whats the best way to get the COM number from query-ing HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM

which gives me:

\Device\VCP0    REG_SZ    COM9                                                                                                                                                      
\Device\VCP1    REG_SZ    COM10

EDIT: I am trying to get the value of data for \Device\VCP0 using this command, but I think I am not escaping backslashes correctly:


1 answer

  • answered 2018-03-14 01:33 Compo

    Here's one way to do it:

    @Echo Off
    Set "CDev=VCP0"
    Set "CNum="
    For /F "Skip=1 Tokens=3" %%A In (
        'Reg Query "%RKey%" /V "\Device\%CDev%" 2^>Nul') Do Set CNum=%%A
    If Not Defined CNum Exit /B
    Rem Your commands below here
    Echo %CNum%
    Timeout 5 >Nul

    You should only ever need to modify the device name on line 2 and place any of your own commands beneath from the Rem line.

    Possible corrections for your straight query command are either:




    There was no need to escape the backslashes in the device name, and a little confusion in root key syntax