I'm trying to get the list of com port name and the device's name connected to it(eg. COM3- Hauewei Modem 3G). I tried the following where I get only the list of com ports.
string [] ports = SerialPort.GetPortNames();
But I need get both the port name along with the device name.
Help me out friends!!
Thanks in advance for your valuable help.
Regards,
Srividhya

VulpesRank #55 · 29.2K reputationPosted Oct 21, 2011, 7:33 AM EDT
However, it does link to a Microsoft WMI tool which may help you to figure it out.
Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 21, 2011, 6:50 AM EDT
Please try the following:
ManagementObjectCollection mReturn;
ManagementObjectSearcher mSearch;
mSearch = new ManagementObjectSearcher("Select * from Win32_SerialPort");
mReturn = mSearch.Get();
foreach (ManagementObject mObj in mReturn)
{
Console.WriteLine(mObj["Name"].ToString());
}
Please do not forget to mark "Accepted Answer".
Sam HobbsRank #108 · 20.5K reputationPosted Oct 21, 2011, 2:34 PM EDT
USB device drivers are totally different; they do not have the traditional COMn name and the API for opening a USB device is different.
So if the device driver is for a COMn type of device it is unlikely Windows can tell you what the device is; perhaps WMI can but I doubt it.
Srividhya Parthasarathy4 reputationPosted Nov 1, 2011, 5:06 AM EDT
Thanks for your answer.. and I'm sorry for late response..
I collated tips from your code and finally succeeded in what I searchd for..
Thanks again for your valuable code.
Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 1, 2011, 8:27 AM EDT