Search code examples
functioninno-setuppascalscript

Inno Setup - Defining a default path inside [code]


I'm trying to read the Windows Registry so my app updates can retrieve the previously saved instalation path as its DefaultDirName.

I've read somewhere that I should call a function, like:

DefaultDirName="{code:GetPath}"

The problem is that I need to define a default path, in case the function does not find a previous one. For instance, 'C:\MyPath'. So I did this:

[Code]
function GetPath(Value: String): String;
var
  OrigPath: string;
begin
  Result := '{sd}\MyPath';
  if RegQueryStringValue(HKCU, 'Software\MyApp', 'PathExec', OrigPath) then
     Result := OrigPath;
end;

That is not working. When I run the setup, at the destination dir dialog I'm getting literally "C:\PathOfMySetup\{sd}\MyPath", not "C:\MyPath".

What should I write at that first "Result := " line in order to "MyPath" be created at the System Drive?

Thanks.


Solution

  • The constants in Pascal Script are not magically expanded. You have to expand them explicitly using the ExpandConstant function:

    Result := ExpandConstant('{sd}\MyPath');