0

I did not find any hidden devices, which are not part of the result list of GetPortNames(). Also there are no additional parameters for GetPortNames().

How to get the list of the existing, but with the hidden serial-ports? (see screenshot, there are hidden entries)

Any hint appreciated.

CODE:

        // Print existing COM-Ports
        var comPorts = SerialPort.GetPortNames();
        Console.WriteLine("Detected COM-Ports:");
        if (comPorts.Length == 0)
        {
            Console.WriteLine(" - NONE -");
        }
        else
        {
            foreach (var item in comPorts)
            {
                Console.WriteLine($" - {item}");
            }
        }

        // new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE Caption like '%(COM%'")    <<< always empty!

RESULT:

  Detected COM-Ports:
   - NONE -

Hidden Serial Ports

SiL3NC3
  • 690
  • 6
  • 29
  • You might have some luck with a WMI query of some sort? Although I can't easily find one which claims to list hidden devices with a quick google – canton7 Jan 24 '23 at 09:59
  • same to me... :| – SiL3NC3 Jan 24 '23 at 10:07
  • 1
    https://stackoverflow.com/a/59822434/1205601 - I cannot use Powershell (it is not allowed in our company) – SiL3NC3 Jan 24 '23 at 10:23
  • It looks like that uses [PnPEntity](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-pnpentity) (run `Get-Command Get-PnPEntity | fl *`), and looks like you might be able to query that [over WMI](https://stackoverflow.com/a/29537661/1086121)? – canton7 Jan 24 '23 at 10:31
  • It isn't obvious what is "hidden" about it. But if it is hidden in Device Manager then it will be hidden to apps as well. The USB device driver might still be loaded but no longer emulate a serial port. Be sure to always, always use "Safely remove hardware" before you disconnect a port. – Hans Passant Jan 24 '23 at 17:59
  • The following may be helpful: https://stackoverflow.com/a/65971845/10024425 (see method _GetComPortInfo_) and https://stackoverflow.com/a/74895268/10024425. I've seen a computer show `COM1`, when nothing is attached. However, after refering to the motherboard documentation, the motherboard happened to have a COM port header which I believe is why a COM port showed up in device manager. – Tu deschizi eu inchid Jan 24 '23 at 19:58

0 Answers0