2

I have configured the below script to ask the user for an IP address as part of the install wizard, this address gets written to a config file which the application will reference to know where to communicate with. However currently, the service is created before the configuration file is updated (Run section happens before CurStep = ssPostInstall), so the default value has already been read from the file before it is updated. This means that a further manual service restart is currently required to get the application to communicate.

I understand it is possible to have the Run section happen after the ssPostInstall.

I have read the article Inno Setup: How to run a code procedure in Run section or before Run section? which suggests I can use the BeforeInstall: parameter as part of the run command to perform the CurStepChanged procedure first. However, this leads to an error of

Required function or procedure 'CurStepChanged' found but not with a compatible prototype.

I also tried moving the run line and command above the CurStepChanged section (to match the article mentioned as closely as possible), but this still returned the same error.

Can anyone offer some guidance as to where I am going wrong with the configuration?

[Code]

var
  PrimaryServerPage: TInputQueryWizardPage;

function FileReplaceString(ReplaceString: string):boolean;
var
  MyFile : TStrings;
  MyText : string;
begin
  Log('Replacing in file');
  MyFile := TStringList.Create;

  try
    Result := true;

    try
      MyFile.LoadFromFile(ExpandConstant('{app}' + '\providers\print\win\print-provider.conf'));
      Log('File loaded');
      MyText := MyFile.Text;

      { Only save if text has been changed. }
      if StringChangeEx(MyText, 'REPLACE_WITH_CUSTOMER_IP', ReplaceString, True) > 0 then
      begin;
        Log('IP address inserted');
        MyFile.Text := MyText;
        MyFile.SaveToFile(ExpandConstant('{app}' + '\providers\print\win\print-provider.conf'));
        Log('File saved');
      end;
    except
      Result := false;
    end;
  finally
    MyFile.Free;
  end;

  Result := True;
end;

procedure InitializeWizard;
begin
  PrimaryServerPage :=
    CreateInputQueryPage(
      wpWelcome, 'Application Server Details', 'Where is installed?',
      'Please specify the IP address or hostname of your ' +
        'Primary Application Server, then click Next.');
  PrimaryServerPage.Add('Primary Application Server IP/Hostname:', False);
end;   

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    Log('File installed, replacing IP address');
    FileReplaceString(PrimaryServerPage.Values[0]);
  end;
end;


[run]
Filename: {sys}\sc.exe; Parameters: "create PCPrintProvider start= auto binPath= ""{app}\providers\print\win\pc-print.exe PCPrintProvider"" depend= Spooler" ; Flags: runhidden ; BeforeInstall: CurStepChanged
Filename: {sys}\sc.exe; Parameters: "start PCPrintProvider" ; Flags: runhidden ; BeforeInstall: CurStepChanged
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Matt
  • 77
  • 1
  • 8

2 Answers2

3

You have to define your own procedure for the BeforeInstall parameter:

[Run]
Filename: {sys}\sc.exe; \
    Parameters: "create PCPrintProvider start= auto binPath= ""{app}\providers\print\win\pc-print.exe PCPrintProvider"" depend= Spooler"; \
    Flags: runhidden; BeforeInstall: ReplaceIPAddress
[Code]

procedure ReplaceIPAddress;
begin
  FileReplaceString(PrimaryServerPage.Values[0]);
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Where should I insert the additional code? I already have the CurStepChanged procedure, is this inserted within that or kept seperate? – Matt Jul 28 '17 at 15:16
  • 1
    Separate. It has nothing to with `CurStepChanged`. And you actually need to remove the `CurStepChanged`. – Martin Prikryl Aug 01 '17 at 04:33
1

Try using Check param

[run]
Filename: {sys}\sc.exe; Parameters: "create PCPrintProvider start= auto binPath= ""{app}\providers\print\win\pc-print.exe PCPrintProvider"" depend= Spooler" ; Flags: runhidden ; Check: IsIpChanged;

[code]
function IsIpChanged: Boolean;
begin
    FileReplaceString(PrimaryServerPage.Values[0]);
    Result := True;
end;
RN92
  • 1,380
  • 1
  • 13
  • 32