function IsPortUsed(aPort: Integer): Boolean; var _vSock: TSocket; _vWSAData: TWSAData; _vAddrIn: TSockAddrIn; begin Result := False; if WSAStartup(MAKEWORD(2, 2), _vWSAData) = 0 then begin _vSock := Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); try if _vSock <> SOCKET_ERROR then begin _vAddrIn.sin_family := AF_INET; _vAddrIn.sin_addr.S_addr := htonl(INADDR_ANY); _vAddrIn.sin_port := htons(aPort); if Bind(_vSock, _vAddrIn, SizeOf(_vAddrIn)) <> 0 then if WSAGetLastError = WSAEADDRINUSE then Result := True; end; finally CloseSocket(_vSock); WSACleanup(); end; end; end;