NSIS - 使用命令行参数跳过某些对话框?

NSIS - Skip certain dialogs using command-line arguments?

有没有办法让 NSIS 安装程序跳过某些对话框?

它有这些命令行参数,

/S/NCRC/D=dir

尽管 /S/NCRC 可用于静默和无人值守模式,是否有命令行参数使安装程序跳过安装程序中的某些对话框并显示对话框的其余部分?例如。跳过欢迎对话框和接下来的两个对话框并转到第四个。

/S、/NCRC 和 /D= 是唯一具有内置支持的安装程序参数,您必须自己处理任何其他参数。

Pages can be skipped by calling Abort in the page pre callback. It is also possible to jump forward a specific number of pagesGetOptions宏可用于解析命令行。

OutFile Test.exe
RequestExecutionLevel user
InstallDir $Temp

!include LogicLib.nsh
!include FileFunc.nsh

Page License LicPre
Page Components CmpPre
Page Directory "" DiShow
Page InstFiles

Var SkippedL
Var SkippedC

!macro AbortIfCmdlineParam Switch Var
${GetParameters} [=10=]
ClearErrors
${GetOptions} [=10=] "${Switch}" [=10=]
${IfNot} ${Errors}
    ${If} ${Var} = 0
        StrCpy ${Var} 1
        Abort
    ${EndIf}
${EndIf}
!macroend

Function LicPre
!insertmacro AbortIfCmdlineParam "/SkipL" $SkippedL
FunctionEnd

Function CmpPre
!insertmacro AbortIfCmdlineParam "/SkipC" $SkippedC
FunctionEnd

Function DiShow
# Disable back button if both pages skipped, this is optional
${If} $SkippedL <> 0
${AndIf} $SkippedC <> 0
    GetDlgItem [=10=] $hwndparent 3
    EnableWindow [=10=] 0
${EndIf}
FunctionEnd

Section
SectionEnd

运行 as Test /SkipL /SkipC 跳过两者。

或:

OutFile Test.exe
RequestExecutionLevel user
InstallDir $Temp

!include LogicLib.nsh
!include FileFunc.nsh

Page License "" LicShow
Page Components
Page Directory
Page InstFiles

Function LicShow
Var /Global HasSkipped
${GetParameters} [=11=]
ClearErrors
${GetOptions} [=11=] "/Skip=" [=11=]
${IfNot} ${Errors}
${AndIf} [=11=] < 4 ; Don't let user skip InstFiles
${AndIf} $HasSkipped = 0
    StrCpy $HasSkipped 1
    SendMessage $HWNDPARENT 0x408 [=11=] ""
${EndIf}
FunctionEnd


Section
SectionEnd

...和 ​​运行 作为 Test /Skip=2.