System.IO.Ports.SerialPort.GetPortNames Method

Gets an array of serial port names for the current computer.

Syntax

public static string[] GetPortNames ()

Returns

An array of serial port names for the current computer.

Remarks

The order of port names returned from SerialPort.GetPortNames is not specified.

Use the SerialPort.GetPortNames method to query the current computer for a list of valid serial port names. For example, you can use this method to determine whether COM1 and COM2 are valid serial ports for the current computer.

The port names are obtained from the system registry (for example, HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM). If the registry contains stale or otherwise incorrect data then the SerialPort.GetPortNames method will return incorrect data.

Requirements

Namespace: System.IO.Ports
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0