4
votes

Since I have dozens of virtual serial (COM) ports installed and the half of them are Bluetooth devices, I'd like to know what port belong to what device and whether it's connecting directly or via Bluetooth.

So in particular I'm not interested in the trivial enumeration of all serial ports, which would only reveal a list of 'COM' + the corresponding number, but the real name of that device and probably its device ID (where information can be found about whether this is connecting via USB or Bluetooth.

While I could get these information via WMI, there are a plenty of problems related to this method. In particular it's bloody slow, but also it does only list connected devices (except for Bluetooth devices, that can potentially be connected and are shown regardless of a real connection)

I'd prefer a solution written in Delphi / Object Pascal, but any other language is also fine for me (the WMI access code was copied from C#).

1

1 Answers

6
votes

If you use a programming language/API that can read the registry, check the subtree HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum.

This has subkeys containing device type, device class, instance ID. Each Instance ID has a subkey Device Parameters\PortName that has the COM name.

For example, on my system

ACPI\PNP0501\1\Device Parameters\PortName = COM1
BTHENUM\{GUID}{ID}\Device Parameters\PortName = COM4

The keys in the ID Part have additional information, for example

ACPI\PNP0501\1\FriendlyName = Kommunikationsanschluss (COM1)  (german windows)
ACPI\PNP0501\1\Service = Serial
BTHENUM\{GUID}{ID}\Service = BTHMODEM

Use regedit to check for yourself which parts are interesting to you. But this should give you all information you need.