0

我遇到了一个有趣的情况,我需要检查机器上是否存在多个程序,然后在安装一些我捆绑在使用 Inno 制作的自定义安装程序包中的软件之前删除它(如果存在)设置。这将搭载以下问题中列出的工作:

我从这里找到了一些好主意。但是,我不确定如何使用它来检查是否安装了多个程序,然后卸载它们。例如,对于我正在尝试构建的自定义安装程序,工作流程看起来像这样:

  • 仅当旧程序 A 不存在时才运行新程序 A 的安装程序。如果旧程序A 存在,则卸载并继续安装新程序A。
  • 仅当旧程序 B 不存在时,才运行新程序 B 的安装程序。如果存在旧程序B,则卸载并继续安装新程序B。
  • 执行一些清理命令,为新安装程序A和新安装程序B的配置添加一些注册表项。
  • 出口

有人建议可能有一种方法可以使用链接脚本中的自定义变量,以便您可以在安装其他捆绑软件之前检查并卸载多个程序。但是,每次我尝试创建新变量或自定义变量时,安装程​​序将不再编译,或者有时它不会按预期工作(即一个程序会卸载而另一个程序不会)。为此,我的问题是关于创建这些自定义变量以及如何使用或扩展它来循环代码,而不是随机尝试一遍又一遍地复制和粘贴同一组代码。我希望这是有道理的。

4

1 回答 1

2

我很确定 TLama 或有经验的人会清理代码,但您可以使用类似的东西进行检查和卸载:

function GetUninstallStringA: string;
var
  sUnInstPathA: string;
  sUnInstallStringA: String;
begin
  Result := '';
  sUnInstPathA := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{{A227028A-40D7-4695-8BA9-41DF6A3895C7}_is1'); //Your AppA GUID/ID
  sUnInstallStringA := '';
  if not RegQueryStringValue(HKLM, sUnInstPathA, 'UninstallString', sUnInstallStringA) then
    RegQueryStringValue(HKCU, sUnInstPathA, 'UninstallString', sUnInstallStringA);
  Result := sUnInstallStringA;
end;

function GetUninstallStringB: string;
var
  sUnInstPathB: string;
  sUnInstallStringB: String;
begin
  Result := '';
  sUnInstPathB := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{{A227028A-40D7-4695-8BA9-41DF6A3895C8}_is1'); //Your AppB GUID/ID
  sUnInstallStringB := '';
  if not RegQueryStringValue(HKLM, sUnInstPathB, 'UninstallString', sUnInstallStringB) then
    RegQueryStringValue(HKCU, sUnInstPathB, 'UninstallString', sUnInstallStringB);
  Result := sUnInstallStringB;
end;

function IsUpgradeA: Boolean;
begin
  Result := (GetUninstallStringA <> '');
end;

function IsUpgradeB: Boolean;
begin
  Result := (GetUninstallStringB <> '');
end;

function InitializeSetup: Boolean;
var
V: Integer;
iResultCodeA, iResultCodeB: Integer;
sUnInstallStringA, sUnInstallStringB: string;
AppA, AppB: Boolean;
    begin
      Result := True; // in case when no previous versions were found
      AppA:= RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{A227028A-40D7-4695-8BA9-41DF6A3895C7}_is1'); //Your AppA GUID/ID
      AppB:= RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{A227028A-40D7-4695-8BA9-41DF6A3895C8}_is1'); //Your AppB GUID/ID
        if (AppA) and (AppB) then begin
          V := MsgBox(ExpandConstant('Hey! Old versions of Apps A and B were detected. Do you want to uninstall them?'), mbInformation, MB_YESNO); 
//Custom Message if App installed
          if V = IDYES then
          begin
            sUnInstallStringA := GetUninstallStringA;
            sUnInstallStringA :=  RemoveQuotes(sUnInstallStringA);
            Exec(ExpandConstant(sUnInstallStringA), '/silent', '', SW_SHOW, ewWaitUntilTerminated, iResultCodeA);
            sUnInstallStringB := GetUninstallStringB;
            sUnInstallStringB :=  RemoveQuotes(sUnInstallStringB);
            Exec(ExpandConstant(sUnInstallStringB), '/silent', '', SW_SHOW, ewWaitUntilTerminated, iResultCodeB);
            Result := True; //if you want to proceed after uninstall
           //Exit; //if you want to quit after uninstall
          end
          else begin
            MsgBox('You have to uninstall older versions of Apps A and B first. Installation will now be terminated.', mbInformation, MB_OK);
            Result := False; //when older versions present and not uninstalled
       end;
      end; 
          if (AppA) and (not AppB) then begin
          V := MsgBox(ExpandConstant('Hey! Old version of App A was detected. Do you want to uninstall it?'), mbInformation, MB_YESNO); 
//Custom Message if App installed
          if V = IDYES then
          begin
            sUnInstallStringA := GetUninstallStringA;
            sUnInstallStringA :=  RemoveQuotes(sUnInstallStringA);
            Exec(ExpandConstant(sUnInstallStringA), '/silent', '', SW_SHOW, ewWaitUntilTerminated, iResultCodeA);
            Result := True; //if you want to proceed after uninstall
           //Exit; //if you want to quit after uninstall
          end
          else begin
            MsgBox('You have to uninstall older version of App A first. Installation will now be terminated.', mbInformation, MB_OK);
            Result := False; //when older versions present and not uninstalled
       end;
      end;  
          if (AppB) and (not AppA) then begin
          V := MsgBox(ExpandConstant('Hey! Old version of App B was detected. Do you want to uninstall it?'), mbInformation, MB_YESNO); 
//Custom Message if App installed
          if V = IDYES then
          begin
            sUnInstallStringB := GetUninstallStringB;
            sUnInstallStringB :=  RemoveQuotes(sUnInstallStringB);
            Exec(ExpandConstant(sUnInstallStringB), '/silent', '', SW_SHOW, ewWaitUntilTerminated, iResultCodeB);
            Result := True; //if you want to proceed after uninstall
           //Exit; //if you want to quit after uninstall
          end
          else begin
            MsgBox('You have to uninstall older version of App B first. Installation will now be terminated.', mbInformation, MB_OK);
            Result := False; //when older versions present and not uninstalled
        end;
       end;
      end;

然后,您可以将 AppA 和 AppB 的新安装程序嵌入到此安装程序中,并通过提取到临时和执行来运行它们。例子:

[Files] 
Source: ".\AppA\setup_appa.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall 
Source: ".\AppB\setup_appb.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall 

[Run] 
Filename: "{tmp}\setup_appa.exe"; Flags: waituntilterminated skipifdoesnotexist; StatusMsg: "Installing App A..." 
Filename: "{tmp}\setup_appa.exe"; Flags: waituntilterminated skipifdoesnotexist; StatusMsg: "Installing App A..."

或者您可以编写 Executing 脚本结合[Files][Code]部分:

嵌入 App A 和 App B 的安装程序:

[Files]
Source: ".\AppA\setup_appa.exe"; DestDir: "{tmp}"; Flags: dontcopy 
Source: ".\AppB\setup_appb.exe"; DestDir: "{tmp}"; Flags: dontcopy

然后调用执行[Code]

[Code]

扩大function InitializeSetup: Boolean;?或放置在其他地方,例如procedure CurPageChanged(CurPageID: Integer);+与...if CurPageID = wpInstalling then
//YOUR RUN SECTION HERE end;

ExtractTemporaryFile('setup_appa.exe');
Exec(ExpandConstant('{tmp}'+'\setup_appa.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
于 2012-08-01T08:44:59.240 回答