I had been using the code below for a console application in Visual Studio on Windows 8 to return the description and device ID of connected serial devices. I was using a mo
A bit smaller solution than Juderb
public static List FindComPorts()
{
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0"))
{
return searcher.Get().OfType()
.Select(port => Regex.Match(port["Caption"].ToString(), @"\((COM\d*)\)"))
.Where(match => match.Groups.Count >= 2)
.Select(match => match.Groups[1].Value).ToList();
}
}
Tested this on win7 + win10. Btw, you can add extra search criteria to the regex if you want (or just add a new Where clause)