In my case, I have physical serial ports, USB serial ports, and com0com virtual serial ports. I need both full names and COM port addresses.
The query suggested in this answer does not find com0com ports. The request suggested in this answer requires administrator privileges.
SELECT * FROM Win32_PnPEntity find all devices. It returns physical devices like this, and the address can be parsed from Caption :
Serial Port for Barcode Scanner (COM13)
However, for com0com Caption ports this is (without address):
com0com - serial port emulator
SELECT * FROM Win32_SerialPort returns addresses ( DeviceID ) as well as full names ( Name ). However, it finds only physical serial ports and com0com ports, not USB serial ports.
So in the end I need two WMI calls: SELECT * FROM Win32_SerialPort ( DeviceID address) and SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%' (address can be parsed from Caption ). I narrowed down the Win32_PnPEntity call because it needs to only find devices that were not found on the first call.
source share