Find which COM ports are available on the machine?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Can anyone tell me how to get a list of which COM ports are available on the
machine? I want to let the user choose from a dropdown list of COM1, COM2,
etc which port he has attached a device to. Can't find a way to get that
list.

thanks
Robb
 
I figured it out...the code below will do it.

private ArrayList getCOMPortList()
{
RegistryKey comPortKey = Registry.LocalMachine.OpenSubKey(
"HARDWARE\\DEVICEMAP\\SERIALCOMM" );

string[] portNames = comPortKey.GetValueNames();

ArrayList comPorts = new ArrayList();

for( int x=0; x<portNames.Length; x++ )
{
string comPortValue = ( string )comPortKey.GetValue( portNames[ x ] );

comPorts.Add( comPortValue );
}

return comPorts;

}
 
Back
Top