在UninstallRun中检查参数功能无法正常工作

问题描述 投票:2回答:1

我想在[Code]section中从[UninstallRun]section获取参数。安装时我在调试输出中“找不到”。我在安装时没有调用CheckGetFile() ...而且在卸载时没有调用GetFilePath()CheckGetFile() .WHY? 这是我的剧本

[Code]
Var
  Check: Boolean;

function GetFilePath(Default: String): String;
begin
  log('GetFilePath()');
  Check := false;
  Result := '';
  { do something }
  if (Found) then
  begin
    Check := true;
    Result := TargetPath;
  end;
end;

function CheckGetFile: boolean;
begin
  if (Check) then
    begin
      log('Found File');
      Result := true;
    end;
  if (not Check) then
    begin
      log('not found');
      Result := false;
    end;
end;

[UninstallRun]
Filename: "{app}\MyApp.exe"; Parameters: "{code:GetFilePath}"; Check: CheckGetFile();

更新

[Code]
Var
  TargetPath: String;

function GetFilePath(): Boolean;
begin
  Result := false;
  { do something }
  if (Found) then
  begin
    TargetPath := 'C:\Windows\xxx';
    Result := true;
  end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
  ResultCode : Integer;    
begin
  if CurUninstallStep = usUninstall then
  begin
    if (GetFilePath) then
    begin
      Exec(ExpandConstant('{app}\MyApp.exe'), '/q /u' + TargetPath, '',
           SW_SHOW, ewWaitUntilTerminated, ResultCode);  
    end;
  end;
end;
inno-setup pascalscript
1个回答
2
投票

Check parameter在安装时间进行评估。您无法在卸载时使用它来检查文件是否存在。

你必须使用[Code]

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
  ResultCode : Integer;    
begin
  if CurUninstallStep = usUninstall then
  begin
    if Check then
    begin
      Exec(ExpandConstant('{app}\MyApp.exe'), '', '',
           SW_SHOW, ewWaitUntilTerminated, ResultCode);  
    end;
  end;
end;
© www.soinside.com 2019 - 2024. All rights reserved.