我遇到了一个有趣的情况,我需要检查机器上是否存在多个程序,然后在安装我在自定义安装程序包中捆绑的某些软件之前将其删除使用Inno Setup制作。这将是以下问题中列出的工作:
我从here找到了一些好主意。但是,我不确定如何使用它来检查是否安装了多个程序,然后卸载它们。例如,对于我正在尝试构建的自定义安装程序,工作流程看起来像这样:
有些人建议可能有一种方法可以使用链接脚本中的自定义变量,这样您就可以在安装其他捆绑软件之前检查并卸载多个程序。但是,每次我尝试创建新的或自定义变量时,安装程序将不再编译,或者其他时候它不会按预期工作(即一个程序将卸载而另一个程序将不会)。为此,我的问题是关于创建这些自定义变量以及如何使用或扩展它来遍历代码而不是随机尝试一遍又一遍地复制和粘贴同一组代码。我希望这是有道理的。
答案 0 :(得分: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的新安装程序嵌入到此程序中,并通过Extracting to 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]
部分的执行脚本:
嵌入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);