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

后端 未结 8 1047
再見小時候
再見小時候 2020-12-05 08:09

I have a GSM modem connected via USB. The modem creates 2 serial ports. The first is automatically attached to the modem, the second shows in Device Manager as \"HUAWEI Mo

8条回答
  •  再見小時候
    2020-12-05 08:30

    After you determine a Serial Port device is the one you want (by looking at its Friendly Name, by checking its parent device etc.), the proper way to get the port's name would probably be:

    • invoke SetupDiOpenDevRegKey(hDevInfo, devInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ) to get the HKEY to the so-called device key
    • query this registry key for the REG_SZ value "PortName"
    • don't forget to close the HKEY :)

    However, this might require so much interop in C# it's not even funny, so I don't blame you if you keep to the string parsing solution.

提交回复
热议问题