我想通过命令行参数更改 NSIS 中的变量。我在文档中看到您可以更改全局变量,但不能在 NSIS 脚本中创建全局变量。
例如:如果我有
Var example
StrCpy $example "C:\Program Files (x86)\Installer"
是否可以通过命令行参数更改示例变量字符串?
最佳答案
OutFile "MySetup.exe"
Name "MySetup"
RequestExecutionLevel user
!include FileFunc.nsh
!include LogicLib.nsh
Var MyVar
Function .onInit
StrCpy $MyVar "Default value"
${GetParameters} $0
ClearErrors
${GetOptions} $0 "/MyVar=" $1 ; Get suffix after "/MyVar=" switch
${IfNot} ${Errors}
StrCpy $MyVar $1
${EndIf}
FunctionEnd
Section
MessageBox mb_OK MyVar:$MyVar
SectionEnd
并作为 "MySetup.exe"/MyVar="Hello world"
执行
关于command-line - 通过命令行 NSIS 安装程序更改变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45176685/