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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With