【问题标题】:Innosetup: sspostinstall executed more than one time?Innosetup:sspostinstall 执行了多次?
【发布时间】:2015-03-19 16:38:49
【问题描述】:

我尝试在(CurrentStep = ssPostInstall)CurStepChanged 过程中执行一个.exe,该.exe 是[Files] 部分的一部分。在我看来,ssPostInstall 似乎被执行了多次——有时甚至在安装过程的文件被处理之前。当然,我可以将 .exe 提取到一个临时文件夹,但我想了解它的行为,这令人失望。每次执行时,到达ssPostinstall 步骤的时刻似乎都会有所不同,有时会不止一次。我错过了什么吗?这是我的代码的一部分:

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; 

提前致谢

克里斯

【问题讨论】:

  • ssPostInstall 步骤的CurStepChanged 事件是trigerred exactly once,就在[Run] 部分is processed 之后,并且请求的应用程序重新启动。所以是你剧本中的其他东西让你有这种感觉。
  • Log 调用添加到您的ssPostInstall 代码并使用/log=log.txt 参数运行安装程序来检查自己。
  • @TLama 所以,即使[RUN] 部分出现错误,ssPostInstall 还是会被触发?

标签: inno-setup post-install


【解决方案1】:

代码中的嵌套和缩进使问题不明显,但是当代码正确缩进时,消息的嵌套错误就会变得更加明显。

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;

注意ErrorCode if 块中缺少begin/end,这意味着单个语句是有条件的。 “没有工作”消息位于 if (CurrentStep=ssPostInstall) thenelse 块中。

这样的东西怎么样(航空代码):

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;

整洁代码的重要性 :p (以及为什么我永远不会错过 {/}begin/end 在块中,即使不需要)

【讨论】:

  • 啊,我想我终于明白了 没有工作 的意思 :) 奇怪的是 有时,但很好!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-12
  • 1970-01-01
  • 1970-01-01
  • 2013-12-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多