Inno Setup: read source path from a registry on compile time

♀尐吖头ヾ 提交于 2020-12-30 03:38:45

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/33348414/inno-setup-read-source-path-from-a-registry-on-compile-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!