How to check if a port is available during install

2019-05-03 00:20发布

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

3条回答
别忘想泡老子
2楼-- · 2019-05-03 00:28

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.

查看更多
欢心
3楼-- · 2019-05-03 00:29

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.

查看更多
神经病院院长
4楼-- · 2019-05-03 00:46

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;
查看更多
登录 后发表回答