简体   繁体   English

如何使用Inno Setup在安装过程中检查端口是否可用?

[英]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. 我正在尝试创建一个安装文件,以便在安装过程中检查一个端口,例如9000,并让用户知道端口状态。 I am new to Inno Setup and wonder if this is possible, and how would I check for this? 我是Inno Setup的新手,想知道这是否可能,我该如何检查呢?

Thank you 谢谢

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;

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 . 您可以直接使用WinAPI调用执行此操作,但您可能会发现使用您选择的语言编写代码以将端口测试到DLL更容易(假设它当然可以创建本机DLL),然后调用此方法从Inno内部

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. 对于Windows 2000,xp版本你可以使用telnet命令,如果win 7,vista,默认情况下没有启用telnet,用户需要从控制面板启用它,或者你可以使用pkgmgr /iu:"TelnetClient"通过它启用它命令行。 from inno you can check the windows version and run the commands accordingly. 从inno你可以检查Windows版本并相应地运行命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM