List of SerialPorts queried using WMI differs from devicemanager?

后端 未结 4 1046
深忆病人
深忆病人 2020-12-17 19:37

I have the following serial ports listed in my devicemanager:

  • COM3
  • COM4 (BT)
  • COM5 (BT)
  • COM6 (GlobeTrotter MO67xx - Control Interface
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-17 19:55

    In my case, I have physical serial ports, USB serial ports, and com0com virtual serial ports. I need both the full names, and COM port addresses.

    The query suggested in this answer does not find com0com ports. The query suggested in this answer requires Administrator priviledges.

    SELECT * FROM Win32_PnPEntity find all devices. It returns physical devices like this, and address can be parsed from Caption:

    Serial Port for Barcode Scanner (COM13)
    

    However, for com0com ports Caption is like this (no address):

    com0com - serial port emulator
    

    SELECT * FROM Win32_SerialPort returns addresses (DeviceID), as well as full names (Name). However, it only finds physical serial ports and com0com ports, not USB serial ports.

    So in the end, I need two WMI calls: SELECT * FROM Win32_SerialPort (address is DeviceID) and SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%' (address can be parsed from Caption). I have narrowed down the Win32_PnPEntity call, because it only needs to find devices that were not found in the first call.

提交回复
热议问题