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
Javeed M ShaikhPosted Nov 1, 2011, 12:27 PM
Srividhya ParthasarathyPosted Nov 1, 2011, 9:06 AM
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.
Sam HobbsPosted Oct 21, 2011, 6:34 PM
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.
VulpesPosted Oct 21, 2011, 11:33 AM
However, it does link to a Microsoft WMI tool which may help you to figure it out.
Javeed M ShaikhPosted Oct 21, 2011, 10:50 AM
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".