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.
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.
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.