.net - Listing of detailed COM port names using VisualStudio 2013 C# -
i want list active com ports detailed names (like in windows device manager). i'm using code , works, slow. can take 45 seconds list of 5 com ports! doing wrong here or there faster way this? know there several postings this, haven't found right answer yet.
private void updateserialports(richtextbox _txtbox) { foreach (string portname in system.io.ports.serialport.getportnames()) { string query = string.format("select * win32_pnpentity caption '%{0}%'", portname); managementobjectsearcher searcher = new managementobjectsearcher("root\\cimv2", query); managementobjectcollection coll = searcher.get(); if (coll.count > 0) { foreach (managementbaseobject collobj in coll) { managementbaseobject obj = collobj; _txtbox.appendtext(portname + " " + obj.getpropertyvalue("caption").tostring() + "\r\n"); } } else { _txtbox.appendtext(new serialport(portname).tostring() + "\r\n"); } } }
Comments
Post a Comment