Inno Setup-注册表uninsdeletekey-排除升级 [英] Inno Setup - Registry uninsdeletekey - exclude upgrade

查看:272
本文介绍了Inno Setup-注册表uninsdeletekey-排除升级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Inno-Setup安装,并且在[Registry]部分中有以下条目

I have an Inno-Setup installation with the following entry in the [Registry] section

Root: HKCU; Subkey: SOFTWARE\MyCompany\MyApp; ValueName: MyKey; Flags: uninsdeletekey noerror

标志中指出的内容将在卸载后删除.

Which as stated by the flags is to be deleted upon uninstall.

但是,我需要保留它,以防由于版本升级而导致卸载.

But I need it to be preserved in case the uninstall is due to version upgrade.

该怎么办? Check也许吗?

谢谢.

推荐答案

您将需要将要保留密钥的信息传递给卸载程序,因为它不知道是谁执行的(嗯,您不需要如果您可以通过编程方式找到父流程,则可以显式传递此信息,但这是一种很简单的方法.

You will need to pass the information that you want to preserve the key to the uninstaller since it doesn't know who executes it (well, you would not need to pass this information explicitly if you'd find the parent process programatically, but it's a rather hacky way).

一种可靠的解决方案是通过命令行参数将此告知卸载程序.下例显示了卸载程序的一种实现,该实现将有条件地删除注册表项:

A reliable solution is telling this to the uninstaller by the command line parameter. One implementation of an uninstaller which will conditionally delete a registry key is shown in the following example:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

#define MyAppRegKey "SOFTWARE\MyCompany\MyApp"

[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命令行参数轻松进行此类安装,则会保留注册表项,否则将其删除,例如:

If you run unistaller of such setup with the /PRESERVEREGKEY command line parameter, the registry key will be preserved, deleted otherwise, e.g.:

unins000.exe /PRESERVEREGKEY


但是,除了您要在两个不同的应用程序之间共享注册表项之外,我无法想到上述的实际用法.通过不同设置安装的应用程序(例如,具有不同 AppId 的安装程序) ).


But I can't think of a real usage of the above other than that you are sharing a registry key between two different applications. Applications installed by a different setup (e.g. a setup with different AppId).

请注意,在进行更新的情况下(如果您要使用相同的

Note that there's no need to uninstall the previous version of your application in case of update (in case when you're installing a new version of the setup with the same AppId). If you will follow this rule, Inno Setup will perform an update and your registry key will be preserved until you uninstall the application.

这篇关于Inno Setup-注册表uninsdeletekey-排除升级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆