Inno Setup:在编译时从注册表读取源路径 [英] Inno Setup: read source path from a registry on compile time
问题描述
从 [Code]
部分读取注册表值非常容易.但是,如果我必须读取要在 [Files]
部分中使用的注册表(安装路径)的值,以便从源文件夹复制文件,则安装/目标文件夹
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
我尝试过:
Source: "{reg:HKLM\SOFTWARE\MyApp,InstallDir|DefaultDirName}\*"; DestDir: "{app}\Mydestination"; AfterInstall: AfterInstallProc
收到错误
未知的文件名前缀'reg:'".
"unknown filename prefix 'reg:'".
或者是否有可能在开始时读取注册表值并将其存储(常量和变量?)以便在 [Files]
部分中使用?
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?
推荐答案
如文档所述,只有在使用 external
标志时才能使用常量:
As documentation says, you can use constants only when you use an external
flag:
常量只能在指定
external
标志时使用,因为编译器本身不会进行任何常量转换.
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.
如果要读取目标计算机上的注册表,则实际上实际上还是要使用 external
标志.
If you want to read the registry on the target machine, you actually want to use the external
flag anyway.
如果您想读取本地注册表,请使用预处理器功能 ReadReg
:
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
设置为:
ISCC.exe Example1.iss /DInstallDir=c:\path
这篇关于Inno Setup:在编译时从注册表读取源路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!