How to show the ports of my pc in a combobox c# windows form?
772
The truth is that I don't know how to start. when we right click and go to Device Manager it shows us a list of connected devices in the ports, now I want to know how I can take that same list to my combobox, I work in windowsForm c#:
Obtaining a list of the available COM ports is very simple, you can use the method GetPortNames:
string[] puertos = SerialPort.GetPortNames();
You must take into account that the namespace must be added System.IO.Ports. This returns puertosComan array of the names of the available serial ports on your system.
As for the LPT ports, things get complicated, since there is no .net method that gives us that information. One 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't test the latter since I don't have any equipment with an LPT port available)
Obtaining a list of the available COM ports is very simple, you can use the method
GetPortNames
:You must take into account that the namespace must be added
System.IO.Ports
. This returnspuertosCom
an array of the names of the available serial ports on your system.As for the LPT ports, things get complicated, since there is no .net method that gives us that information. One possible solution is to use a WMI query:
(Unfortunately I can't test the latter since I don't have any equipment with an LPT port available)