1

In a innosetup installer, my goal is to configure the Windows firewall to open the adequate port for my software

[Run]
Filename: "{sys}\netsh.exe"; Parameters: "firewall set portopening protocol=TCP port=""{code:GetServerPort()}"" name=NxTCP mode=ENABLE"; StatusMsg: "Opening TCP Port ""{code:GetServerPort()}"; Flags: runhidden

[Code]
function GetServerPort(): String;
begin
  Result := "5555"; //obtained with the Wizard
end;

And I get this error

Required function or procedure 'GetServerPort()' not found.

Or if I drop the () at the call

Invalid prototype for 'GetServerPort'

Sandburg
  • 757
  • 15
  • 28

1 Answers1

5

This code works for me:

[Run]
Filename: "{sys}\netsh.exe"; Parameters: "firewall set portopening protocol=TCP port=""{code:GetServerPort}"" name=NxTCP mode=ENABLE"; StatusMsg: "Opening TCP Port ""{code:GetServerPort}"; Flags: runhidden


[Code]
function GetServerPort(Value: string): String;
begin
  Result := '5555'; //obtained with the Wizard
end;

Your function call in the [Run] is not properly formatted. The {code:XXX} is basically a Check parameter and is documented at http://www.jrsoftware.org/ishelp/topic_scriptcheck.htm

mirtheil
  • 8,952
  • 1
  • 30
  • 29
  • So it was all a question of signature? Adding a mystical `Value: String` goes. – Sandburg Feb 08 '19 at 14:07
  • `{code:XXX}` is not a `Check` parameter. `Check` parameter actually does not require the `string` argument, while `{code}` does. See [“Identifier Expected” or “Invalid Prototype” when implementing a scripted constant in Inno Setup](https://stackoverflow.com/q/33656548/850848). – Martin Prikryl Feb 16 '19 at 16:12