Inno Setup使用{reg}常量引用包含括号的注册表项 [英] Inno Setup referencing a Registry key containing braces using the {reg} constant

查看:126
本文介绍了Inno Setup使用{reg}常量引用包含括号的注册表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对DefaultDirName使用{reg}常量,该常量引用包含括号的路径:

I am trying to use the {reg} constant for DefaultDirName where it references a path that contains braces:

  DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{3E4A76D9-EC0E-4806-915C-8BC2B3C0011B},InstallLocation}

但是,这不起作用,因为编译器认为路径中的GUID是常量.如果我尝试按照建议的方法用另一个大括号将大括号转义(请参见下文),则此方法也不起作用,并显示无效的注册表常量"错误.

However, this does not work as the compiler thinks the GUID in the path is a constant. If I try and escape the brace with another brace as suggested (see below) this does not work either and gives an 'Invalid registry constant' error.

  DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{{3E4A76D9-EC0E-4806-915C-8BC2B3C0011B},InstallLocation}

我尝试了所有可以想到的组合来尝试逃避此问题,并使编译器认识到这一点,包括使用%7d尝试强制使用右括号,如文档中所建议的那样,但这似乎并没有在这种情况下编译为结束括号.希望有人可以建议如何使编译器识别该注册表位置,或者至少告诉我是否我正在尝试做一些不可能的事情.如果是这样,还有其他方法可以尝试这种方法吗?鉴于我也已经尝试过:

I have tried all combinations I can think of to try and escape this and get the compiler to recognise this, including using %7d to try and force a closing brace, as suggested in the documentation as well, but this does not seem to compile to a closing brace in this situation. Hopefully someone can advise how to get the compiler to recognise this Registry location or at least tell me whether I am attempting to do something that is not possible. If so, is there another way to attempt this? Given that I have also already tried:

  DefaultDirName={code:GetExistingInstallPath}
  [Code]
  function GetExistingInstallPath(Param: String): String;
  begin
    RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F34A6950-7E0E-4F92-8B0E-C552F4989DA}',
'InstallLocation', strExistingInstallPath);
    Result := strExistingInstallPath;
  end;

确实可以编译,但是strExistingInstallPath不返回任何内容,并且将鼠标悬停在{code:GetExistingInstallPath}上将返回异常:由于可能的副作用,无法评估"code"常量.经过几个小时的尝试,我几乎可以断定Inno安装程序不支持包含花括号的注册表位置.

which does compile, but the strExistingInstallPath returns nothing and hovering over the {code:GetExistingInstallPath} returns an 'Exception: Cannot evaluate "code" constant because of possible side effects.' After a couple of hours trying to get this working, I am getting close to concluding that Inno Setup does not support Registry locations containing braces.

请注意,我需要阅读此注册表项,因为Inno Setup尚未安装该软件,而这是一个替换文件的补丁程序,因此我需要知道它最初安装在何处.

Note, that I need to read this Registry key as the software was not installed by Inno Setup and this is a patch to replace a file, so I need to know where it was originally installed to.

推荐答案

如果使用

In case of using {reg:...} instead of closing } you have to use %7d

示例:

DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\
{{‌​3E4A76D9-EC0E-4806-915C-8BC2B3C0011B%7d,InstallLocation}

如果没有使用ExpandConstant,则在[Code]部分中阅读注册表"时,不必使用两次打开{{

When reading Registy in [Code] section if there is NO ExpandConstant used, you do not have to use double opening {{

示例:

RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\
{3E4A76D9-EC0E-4806-915C-8BC2B3C0011B}','InstallLocation', strExistingInstallPath);

P.S.感谢@Tlama指出我的不准确.

P.S. Thanks @Tlama for pointing out my inexactness.

这篇关于Inno Setup使用{reg}常量引用包含括号的注册表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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