0

我的目標是知道在使用靜默安裝(/ S參數)將NSIS命令行參數傳遞給複製設置時是否使用任何檢查或代碼snipp來確定是否有某種依賴性。 。在NSIS腳本中使用命令行參數實現依賴關係檢查

的NSIS樣品:http://nsis.sourceforge.net/Get_command_line_parameter_by_name

例如,如果我有三個PARAMS:的Setup.exe/S參數1 = 「」 參數2 = 「」 參數3 = 「」

如何檢查以下secanrio:

${if} <Param1 is passed to Setup.exe> 
    <Param2 must ALSO be passed to Setup.exe> 
${else} 
    <Error message notifiing that Param1 is present, but dependent Param2 param is missing in CMD parameters> 

謝謝!

我真的希望你會分享至少代碼snipp ...如果不是全部功能代碼。

回答

0
outfile test.exe 
requestexecutionlevel user 
silentinstall silent ;always force silent in this sample 
!include LogicLib.nsh 
!include FileFunc.nsh 

Function StripOptPrefix 
Exch $0 
Push $1 
StrCpy $1 $0 1 
${If} $1 == "=" 
${OrIf} $1 == ":" 
    StrCpy $0 $0 "" 1 
${EndIf} 
Pop $1 
Exch $0 
FunctionEnd 
!macro StripOptPrefix var 
Push ${var} 
call StripOptPrefix 
Pop ${var} 
!macroend 

Section 
${GetParameters} $0 
${If} $0 == "" 
    ;No parameters, lets run the tests 
    ExecWait '"$exepath" /param1=foo' 
    ExecWait '"$exepath" /param1=foo /param2=bar' 
${Else} 
    ${GetOptions} $0 "/param1" $1 
    ${If} ${Errors} 
     # /param 1 not used, do nothing? 
    ${Else} 
     ${GetOptions} $0 "/param2" $2 
     ${If} ${Errors} 
      MessageBox mb_iconstop "Missing /param2, required by /param1" 
      Quit 
     ${Else} 
      !insertmacro StripOptPrefix $1 
      !insertmacro StripOptPrefix $2 
      MessageBox mb_ok "1=$1$\n2=$2" 
     ${EndIf} 
    ${EndIf} 
${EndIf} 
SectionEnd 
相關問題