NSIS 无人值守选项

标签 nsis unattended-processing

我想构建一个 NSIS 脚本,它分为三个部分

  • 主要部分
  • 次要部分
  • 共享部分

如果选中 Main 或 Minor,Shared 是不可见的并且会被安装。如果我启动安装程序,则会检查每个部分(主要、次要)。

现在它应该能够定义该部分(在静默安装中)。我需要更改什么,仅安装主要或次要或两者?

最佳答案

Name "Test"
Outfile "Test.exe"
;RequestExecutionLevel ?

!include "Sections.nsh"
!include "LogicLib.nsh"
!include "FileFunc.nsh" ;For GetOptions

Page Components "" "" EnforceSectionDependencies
Page InstFiles

Section /o "Main" SID_MAIN
DetailPrint Main
SectionEnd

Section /o "Minor" SID_MINOR
DetailPrint Minor
SectionEnd

Section "" SID_SHARED
DetailPrint Shared
SectionEnd

!macro CheckSectionSwitch sw sid
${GetOptions} $0 '${sw}' $9
${IfNot} ${Errors}
    StrCpy $1 1
    !insertmacro SelectSection ${sid}
${EndIf}
!macroend

Function .onInit
${GetParameters} $0
StrCpy $1 0 ;Any section swithes?
ClearErrors
!insertmacro CheckSectionSwitch '/Main' ${SID_MAIN}
!insertmacro CheckSectionSwitch '/Minor' ${SID_MINOR}

${If} $1 = 0
    ;Set defaults
    !insertmacro SelectSection ${SID_MAIN}
    !insertmacro SelectSection ${SID_MINOR}
${EndIf}

call EnforceSectionDependencies
FunctionEnd

Function EnforceSectionDependencies
!insertmacro UnselectSection ${SID_SHARED}
${If} ${SectionIsSelected} ${SID_MAIN}
${OrIf} ${SectionIsSelected} ${SID_MINOR}
    !insertmacro SelectSection ${SID_SHARED}
${EndIf}
FunctionEnd

关于NSIS 无人值守选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11080412/

相关文章:

postgresql - 将密码作为参数传递给 NSIS 中的 psql 命令

visual-studio-2015 - 如何为Windows 10 HWA bundle 创建安装程序?

windows - 以管理员身份运行时获取当前登录的用户

.net - NSIS:查找并下载 .Net 版本

windows - 导出区域设置供以后导入

nsis - ReadRegStr 失败

powershell - 如何使用 powershell 安装 Azure cmdlet

powershell - 未经手动接受,无法使用注册表项远程卸载 Google Chrome

windows-installer - 确定 MSI/EXE 是否支持某些标志/参数?