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

I am trying to create an installation file, so during installation it will check the port, say 9000, and tell the user the status of the port. I am new to Inno Setup and wondering if this is possible, and how can I test it?

thanks

+4
source share
3 answers

you can use my function to check port availability

cm.:

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; 
+5
source

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 are checking).

You can do this directly using WinAPI calls, but it will probably be easier for you to write the code for checking the port in the DLL using the language of your choice (provided that it can create its own DLL files, of course) and then name it from the inside Inno .

+2
source

For Windows 2000, xp versions, you can use the telnet command, if win 7, vista, telnet is not enabled by default, the user must enable it from the control panel or you can use pkgmgr /iu:"TelnetClient" to enable it through the line command . from inno you can check the version of Windows and execute the appropriate commands.

+1
source

Source: https://habr.com/ru/post/1439219/


All Articles