I am trying to obtain the available/defined comports using this code but am getting a compiler error stating
The type or namespace name 'ManagementObjectSearcher' does not exist in the namespace 'System.Management' (are you missing an assembly reference?)
Do you guys have any ideas on how I can get this to compile?
using (var searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE Caption like '%(COM%'"))
{
var portnames = SerialPort.GetPortNames();
var ports = searcher.Get().Cast<ManagementBaseObject>().ToList().Select(p => p["Caption"].ToString());
var portList = portnames.Select(n => n + " - " + ports.FirstOrDefault(s => s.Contains(n))).ToList();
for( int i=0; i < portList.Count; i++)
{
var s = portList[i];
if (s.Contains("Prolific"))
{
strComPort = portnames[i];
}
}
}