我有一个Inno-Setup安装,在[Registry]
部分中有以下条目
Root: HKCU; Subkey: SOFTWAREMyCompanyMyApp; ValueName: MyKey; Flags: uninsdeletekey noerror
如标志所述,卸载时将删除。
但是我需要保留它,以防卸载是由于版本升级造成的。
怎么能做到呢? Check
也许?
谢谢。
要保留密钥的信息传递给卸载程序,因为它不知道谁执行它(好吧,如果您以编程方式找到父进程,则不需要显式传递此信息,但这是一种相当黑客的方式(。
一个可靠的解决方案是通过命令行参数将此告诉卸载程序。以下示例显示了将有条件地删除注册表项的卸载程序的一种实现:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}My Program
#define MyAppRegKey "SOFTWAREMyCompanyMyApp"
[Registry]
; no uninsdeletekey flag must be used here
Root: HKCU; Subkey: "{#MyAppRegKey}"; Flags: noerror
Root: HKCU; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "MyKey"; ValueData: "MyValue"; Flags: noerror
[Code]
function CmdLineParamExists(const Value: string): Boolean;
var
I: Integer;
begin
Result := False;
for I := 1 to ParamCount do
if CompareText(ParamStr(I), Value) = 0 then
begin
Result := True;
Exit;
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
// if we are at the post uninstall step and the uninstaller wasn't executed with
// the /PRESERVEREGKEY parameter, delete the key and all of its subkeys (here is
// no error handling used, as your original script ignores all the errors by the
// noerror flag as well)
if (CurUninstallStep = usPostUninstall) and not CmdLineParamExists('/PRESERVEREGKEY') then
RegDeleteKeyIncludingSubkeys(HKCU, '{#MyAppRegKey}');
end;
如果使用 /PRESERVEREGKEY
命令行参数运行此类安装程序的 unistaller,则注册表项将被保留,否则将被删除,例如:
unins000.exe /PRESERVEREGKEY
但是除了您在两个不同的应用程序之间共享注册表项之外,我想不出上述内容的真正用法。由不同设置安装的应用程序(例如,具有不同AppId
的设置(。
请注意,在更新时无需卸载应用程序的先前版本(以防安装具有相同AppId
的安装程序的新版本(。如果您遵循此规则,Inno 安装程序将执行更新,并且您的注册表项将保留,直到您卸载应用程序。