Mega Code Archive

 
Categories / Delphi / Hardware
 

How can I determine the names of the installed comm ports

Title: How can I determine the names of the installed comm ports? Question: How can I determine the names of the installed comm ports? Answer: The following example demonstrates enumerating the communications ports that are installed and listed in the Win32 registry. uses Registry; procedure TForm1.Button1Click(Sender: TObject); var reg : TRegistry; ts : TStrings; i : integer; begin reg := TRegistry.Create; reg.RootKey := HKEY_LOCAL_MACHINE; reg.OpenKey('hardware\devicemap\serialcomm', false); ts := TStringList.Create; reg.GetValueNames(ts); for i := 0 to ts.Count -1 do begin Memo1.Lines.Add(reg.ReadString(ts.Strings[i])); end; ts.Free; reg.CloseKey; reg.free; end;