0

I try to execute an .exe in the CurStepChanged procedure at (CurrentStep = ssPostInstall), the .exe is part of the [Files] section. It seems to me as if the ssPostInstall is executed multiple times – sometimes even before the files of the installation process are processed. Of course I could extract the .exe to a temporary folder but as I would like to understand the behavior it’s disappointing. The moment when the ssPostinstall step is reached seems to vary every time I execute and sometimes is reached more than one time. Am I missing something? Here is a part of my code:

procedure CurStepChanged(CurrentStep: TSetupStep);

var  ErrorCode : Integer;

begin
  if (CurrentStep = ssPostInstall) then begin
    if Exec(ExpandConstant('{app}\{code:getVersionSubdir}\licencing\haspdinst.exe'), '-i', '',SW_SHOW, ewWaitUntilTerminated, ErrorCode) then 
    begin
       if ErrorCode = 0 then      else
          MsgBox(SysErrorMessage(ErrorCode), mbCriticalError, MB_OK);
       end;
    end     
    else begin
         MsgBox('Did not work', mbCriticalError, MB_OK);      
    end;
end; 

Thanks in advance

Chris

CKRYZ
  • 3
  • 3
  • 1
    The `CurStepChanged` event for the `ssPostInstall` step is [`trigerred exactly once`](https://github.com/jrsoftware/issrc/blob/is-5_5_5/Projects/Main.pas#L3890), right after the `[Run]` section [`is processed`](http://jrsoftware.org/ishelp/topic_installorder.htm) and the requested applications restarted. So it's something else in your script that makes you feel this way. – TLama Mar 18 '15 at 14:58
  • 1
    Add [`Log`](http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_log) call to your `ssPostInstall` code and run the installer with `/log=log.txt` parameter to check yourself. – Martin Prikryl Mar 18 '15 at 15:00
  • @TLama So, Even if the section `[RUN]` finished with errors, the `ssPostInstall ` is trigerred anyway ? – Amlys Sep 29 '20 at 10:16

1 Answers1

2

The nesting and indentation in your code makes the issue non obvious, but hen the code is indented correctly, it becomes a lot more obvious that the nesting of your messages is wrong.

procedure CurStepChanged(CurrentStep: TSetupStep);
var ErrorCode : Integer;
begin
  if (CurrentStep = ssPostInstall) then
  begin
    if Exec(ExpandConstant('{app}\{code:getVersionSubdir}\licencing\haspdinst.exe'), '-i', '',SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
    begin
      if ErrorCode = 0 then
      else
        MsgBox(SysErrorMessage(ErrorCode), mbCriticalError, MB_OK);
    end;
  end
  else
  begin
    MsgBox('Too early? Did not work', mbCriticalError, MB_OK);
  end;
end;

Note the lack of begin/end in the ErrorCode if blocks meaning a single statement is conditional. The "did not work" message is in the else block of the if (CurrentStep=ssPostInstall) then.

How about something like this (air code):

procedure CurStepChanged(CurrentStep: TSetupStep);
var ErrorCode : Integer;
begin
  if (CurrentStep = ssPostInstall) then
  begin
    if not Exec(ExpandConstant('{app}\{code:getVersionSubdir}\licencing\haspdinst.exe'), '-i', '',SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
    begin
      // Exec returned failure
      MsgBox('Did not work', mbCriticalError, MB_OK);
    end;
    else if ErrorCode <> 0 then
    begin
      // Exec returned success but non 0 error code
      MsgBox(SysErrorMessage(ErrorCode), mbCriticalError, MB_OK);
    end;
    // Else here if you want to do something on success
  end;
end;

The importance of tidy code :p (And why I never miss out {/} and begin/end in blocks, even when not needed)

Deanna
  • 23,876
  • 7
  • 71
  • 156
  • Ah, I think I finally got what *did not work* means :) Weird is that *sometimes*, but good catch! – TLama Mar 19 '15 at 10:08