I am trying to access specific information about Bluetooth serial ports. I was able to find this window in my Bluetooth settings that showed me the port, direction, and name of a Bluetooth device if it was related to a COM Port.
Currently to try and get this information, I have been using WQL to query some of the Windows Management Classes.
# I don't really mind if it is run in a Powershell environment
gwmi -query "SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%COM%' AND PNPDeviceID LIKE '%BTHENUM%' AND PNPClass = 'Ports'"
//or a C# environment
ManagementObjectCollection results = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%COM%' AND PNPDeviceID LIKE 'USB%' AND PNPClass = 'Ports'").Get();
#This is a lot slower but it gets a bit more information about the serial ports
gwmi -query "SELECT * FROM Win32_SerialPort WHERE Name LIKE '%COM%' AND PNPDeviceID LIKE '%BTHENUM%'"
However, the queries below do not include the name (as it is in the screenshot) and the direction of the COM Ports. Is it possible to get this information using WQL?
Whilst I'm not sure if this can be done 100% with WQL, I was able to write a small program in C# that handled it.
It works by looking for patterns in some of the Win32_PnPEntity properties.
It extracts an identifier out of all the stored bluetooth devices and compares that identifier with the same identifier on the COM ports. If it finds it, it has found the outgoing COM port.
Both the outgoing and incoming port have a similar hardware ID, where the first part is identical. Using this information, the program then identifies incoming COM port if it exists.
To get it in the format shown in the image in the question, it is possible to run a powershell command that queries the
DEVPKEY_Device_BusReportedDeviceDesc
of the outgoing port. This is the'Dev B'
part of the name on the outgoing port.This all done asynchronously so the list is populated as the results are found.
XAML
C#