如何使用 NSIS 始终在目标安装中添加默认文件夹

How to add a default folder always with target installation using NSIS

我想始终在内部将默认目录附加到我的 INSTALL 目录。 我默认设置了它,但如果用户更改目录,则它不起作用并将文件安装在用户选择的文件夹中。

所以我需要始终在内部附加一个文件夹(产品名称),它可以附加用户选择的路径。

如果用户选择 "C:\Program Files\My Folder" 那么安装应该在路径 "C:\Program Files\My Folder\ProductName" 也应该与沉默一起工作。 有人可以就此提出建议吗?

Section MyFirstSection
StrCpy $InstDir "$InstDir\ProductName" ; Force extra sub-directory
; ...
SectionEnd

但是,推荐的方法是只使用 InstallDir 而没有结束反斜杠:

Note that the part of this string following the last \ will be used if the user selects 'browse', and may be appended back on to the string at install time (to disable this, end the directory with a \ (which will require the entire parameter to be enclosed with quotes).