Using ManagementObjectSearcher for serial port list

C

Claire

I'm using the following code in an attempt to obtain a list of available
serial ports.
I expected to retrieve the same values as listed in hardware manager in
Control panel but I'm not.
I'm being returned COM1 and COM3 when I should be receiving COM1 and COM4.
I've also a USB to serial converter and although listed in control panel
correctly again my query is not returning this device.
What am I doing wrong please?

public void FillDeviceList(ComboBox.ObjectCollection cb)
{
cb.Clear();
SelectQuery selectQuery = new SelectQuery("select * from Win32_SerialPort");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(selectQuery);
//System.Array result
foreach (ManagementObject disk in searcher.Get())
{
cb.Add(disk["DeviceID"].ToString());
}
}
 
G

Guest

Claire, I think this has to do with physical as against virtual ports

My notebook PC hos no hardware COM ports, but the hardware manager shows 3 virtual ports (COM4, COM5, COM6)
Your query returns nothing
On the other hand, I have 4 physical USB ports. These are listed when I use the "Win32_USBHub" query

In your case if you have only 1 physical COM port, it will be both COM1 and COM3
Your USB to serial converter will be a virtual COM port that's why it doesn't show.
 
C

Claire

thanks crater,
that answers why i'm getting com3.
So my problem is how to query for virtual com ports and how to filter out
ports like com3.
If microsoft achieve this then I should be able to do the same if I knew
what I was looking for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top