Enum Com Ports

I need to enum all the comports under Windows NT. Is there an API function to do this.

Im using Delphi V5.
ggetsAsked:
Who is Participating?
 
interConnect With a Mentor Commented:
Hi,
the following shows the available ports(1-8) and indicate the opened ones as well. You may change it for your purpose or ask from me...

procedure ShowComPorts;
var
  I : Integer;
  h : THandle;
  S : string;
begin
  S :='';
  for I := 1 to 8 do
  begin
    H := CreateFile(PChar('COM'+InTToStr(I)), GENERIC_READ, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);
    if H <> INVALID_HANDLE_VALUE then
    begin
      s:= s+'COM'+InTToStr(I)+#13#10;
      CloseHandle(H);
    end else if GetLastError = ERROR_ACCESS_DENIED then
      s:= s+'COM'+InTToStr(I)+' opened'+#13#10;
  end;
  ShowMessage(S);
end;


regards, igor
0
All Courses

From novice to tech pro — start learning today.