[delphi] aantal comm. poorten opvragen

Pagina: 1
Acties:

  • wizl
  • Registratie: Maart 2001
  • Laatst online: 27-02-2023
Hoe kan ik in delphi het aantal comm. poorten in windows opvragen (COM: en LPT:)?

edit:

never mind, ik check wel in de registry :P

  • Ariejan
  • Registratie: Februari 2001
  • Laatst online: 02-09 16:31
[evermind]
Je zou es kunnen kijken naar bepaalde opensource components die system info geven. Misschien dat je daar wat wijzer van wordt.
[/evermind]

Verwijderd

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function IsPortAvailable(APort: string): boolean;
var
  h: integer;
begin
  Result := False;
  h := CreateFile(PChar(APort), // 'COM1:', 'COM2:', etc.
            GENERIC_READ or GENERIC_WRITE,
            0, // do not share
            nil, // default security attributes
            OPEN_ALWAYS,
            FILE_ATTRIBUTE_NORMAL,
            0);
  if h <> INVALID_HANDLE_VALUE then begin
    Result := True;
    CloseHandle(h);
  end;
end;

Gewoon voor COM1 t/m 64 en LPT1 t/m 8 of zo opvragen. Lijkt me ietsje safer dan checken in de registry.