registryinno-setup

Read source path from a registry on compile time in Inno Setup


Reading a registry value from the [Code] section is quite easy. But if I have to read the value of a registry (an installation path) to be used in the [Files] section in order to copy files from a source folder the the install/destination folder

I tried:

Source: "{reg:HKLM\SOFTWARE\MyApp,InstallDir|DefaultDirName}\*"; \
    DestDir: "{app}\Mydestination"; AfterInstall: AfterInstallProc

receiving the error

"unknown filename prefix 'reg:'".

Or is there a possibility to read a registry value at the beginning and storing it (a constant? and variable?) in order to be used in the [Files] section?


Solution

  • As documentation says, you can use constants only when you use an external flag:

    Constants may only be used when the external flag is specified, because the compiler does not do any constant translating itself.

    It's because the constants are resolved on run-time, while the (non-external) files are compiled into the installer on compile time.

    If you want to read the registry on the target machine, you actually want to use the external flag anyway.


    If you want to read local registry, use pre-processor function ReadReg:

    Source: "{#ReadReg(HKLM, "SOFTWARE\MyApp", "InstallDir", "DefaultDirName")}\*"; \
        DestDir: "{app}\Mydestination"; AfterInstall: AfterInstallProc
    

    Though I'd personally prefer a value set on the command-line of the compiler:

    Source: "{#InstallDir}\*"; DestDir: "{app}\Mydestination"; \
        AfterInstall: AfterInstallProc
    

    Set as:

    ISCC.exe Example1.iss /DInstallDir=c:\path