Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a port is available during installation using Inno Setup?

I am trying to create a setup file, so that during installation it will check a port, say 9000, and let user know the port status. I am new to Inno Setup and wonder if this is possible, and how would I check for this?

Thank you

like image 753
user1738909 Avatar asked Oct 11 '12 17:10

user1738909


3 Answers

you can use my function to check a port is available

see :

  function CheckPortOccupied(Port:String):Boolean;
  var
    ResultCode: Integer;
  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;
like image 100
LEo Avatar answered Oct 11 '22 17:10

LEo


The only real way to see if a port is available is to try connecting or listening to it (depending on what kind of availability you're checking for).

You can do this with WinAPI calls directly, but you'd probably find it easier to write the code to test the port into a DLL using the language of your choice (provided that it can create native DLLs of course), and then call this from within Inno.

like image 36
Miral Avatar answered Oct 11 '22 17:10

Miral


For windows 2000, xp versions you can use telnet command, if win 7, vista, the telnet is not enabled by default, the user needs to enable it from control panel or you can use pkgmgr /iu:"TelnetClient" to enable it thru command line. from inno you can check the windows version and run the commands accordingly.

like image 28
anand Avatar answered Oct 11 '22 15:10

anand