2017-07-18 122 views
2

我想通過命令行參數更改NSIS中的變量。我在文檔中看到可以更改全局變量,但在NSIS腳本中沒有創建全局變量。通過命令行更改變量NSIS安裝程序

例如:如果我有

Var example 
StrCpy $example "C:\Program Files (x86)\Installer" 

是否有可能改變通過命令行參數的例子變量字符串?

回答

3
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"