How to display the ports of my pc in a combobox c # windows form?

0

The truth is that I do not know how to start. when we right click and go to Device Manager shows us in the ports a list of connected devices, now I want to know how I can bring that same list to my combobox, work in windowsForm c #:

    
asked by Rodrigo Rodriguez 16.10.2017 в 22:18
source

1 answer

3

Obtaining a list of available COM ports is very simple, you can use the GetPortNames :

string[] puertos = SerialPort.GetPortNames();

You must bear in mind that you must add the namespace System.IO.Ports . This returns in puertosCom an array with the names of the serial ports available in your system.

As for the LPT ports the thing is complicated, since there is no .net method that gives us that information. A possible solution is to use a WMI query:

var parallelPort = new ManagementObjectSearcher("Select * From Win32_ParallelPort");
foreach (var rec in parallelPort.Get())
{
    Console.WriteLine(rec.Properties["Name"]);
}

(Unfortunately, I can not prove this since I do not have any equipment with an LPT port available)

    
answered by 17.10.2017 / 13:07
source