Inno Setup referencing a Registry key containing b

2019-05-14 21:28发布

问题:

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}

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}

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;

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.

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.

回答1:

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

Example:

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

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

Example:

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

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



标签: inno-setup