2012-07-31 168 views
0

我遇到了一个有趣的情况,我需要检查机器上是否存在多个程序,然后在安装某些软件之前将其删除捆绑在用Inno Setup制作的自定义安装程序包中。这将被捎带关在下列问题中列出的工作:使用自定义安装程序卸载多个程序

我已经发现了一些好的想法来自here。但是,我不确定如何使用它来检查是否安装了多个程序,然后将其卸载。例如,工作流会是这个样子的自定义安装程序,我想建立:

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

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

+0

对不起,但我不知道我得到了你问的。你已经提到你需要有条件地检查* programA *或* programB *是否在运行时从主设置中安装。然后你问*我的问题是关于创建这些自定义变量以及如何使用或扩展来循环代码,而不是随机尝试复制和粘贴相同的一组代码*似乎是什么关于预处理器的问题。所以对我来说这没有意义。你能指定这些变量何时何地来自哪里,他们的意图是什么? – TLama 2012-08-01 06:20:01

+1

对于多个应用程序没有什么特别之处,只需重复代码并对其进行修改即可检查相应的应用程序。什么是其他应用程序安装程序写入?如果Inno,仍然不需要首先进行卸载,并且如果他们确实需要卸载,那么它应该是安装程序的逻辑,使您的包装更简单。 – Deanna 2012-08-01 09:45:05

+0

@Deanna,这对于预处理器来说是最好的任务......反正OP没有提到他想升级这些应用程序,只是卸载。 – TLama 2012-08-01 11:18:45

回答

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加入到这一个中,并通过提取到temp和Executing来运行它们。 例子:

[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..." 

或者你可以编写执行脚本合成[Files][Code]部分:

应用程序A和应用B的embeding安装:

[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);