How to see if a port is in use in Inno Setup?

3

In my installer created with Inno Setup it was necessary to check the availability of a port to install and mount a MySQL service, since if the port is in use it is necessary to change it.

    
asked by Angel Montes de Oca 31.05.2017 в 01:51
source

1 answer

2

After trying many methods to perform them, I found a way to do it:

[CODE]

function CheckPortOccupied(Port:String):Boolean;
var
  ResultCode: Boolean;
begin
  Exec(ExpandConstant('{cmd}'), '/C netstat -na | findstr'+' /C:":'+Port+' "', '', 0,
       ewWaitUntilTerminated, ResultCode);
  if ResultCode <> 1 then 
  begin
   // Log('this port('+Port+') is occupied');
    Result := True; 
  end
    else
  begin
    Result := False;
  end;
end;

how to implement it:

function NextButtonClick(CurPageID: Integer): Boolean;
var
ocupado : Boolean;

begin
Result := True;
  if (CurPageID = Pagina.ID) then
    begin
      ocupado := CheckPortOccupied('80');
        if (ocupado = True)then
          begin
          Result := False;
          MsgBox('El Puerto '+fieldPuertoServerPage.text+' esta ocupado',mbError,MB_OK)
          end;
    end;
end;

I hope it helps you.

    
answered by 31.05.2017 / 01:51
source