NSIS获取命令行参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | !include "FileFunc.nsh" !insertmacro GetOptions !insertmacro GetParameters Name "Pass2Go" OutFile "AiRoboForm-Portable.exe" page directory Section "" SetOutPath $INSTDIR File Pass2Go.nsi SectionEnd Function .onInit ; SetSilent silent ${GetParameters} $R0 ${GetOptions} $R0 "/unpack=" $R1 MessageBox MB_OK $R0 StrCpy $INSTDIR $R1 FunctionEnd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ____________________________________________________________________________ GetOptions ____________________________________________________________________________ Get options from command line parameters. Syntax:${GetOptions} "[Parameters]" "[Option]" $var "[Parameters]" ; command line parameters ; "[Option]" ; option name ;$var ; Result: option string Note: -Error flag if option not found -First option symbol it is delimiter |
Example1:
1 2 3 4 5 6 | Section ${GetOptions} "/S /T" "/T" $R0 IfErrors 0 +2 MessageBox MB_OK "Not found" IDOK +2 MessageBox MB_OK "Found" SectionEnd |
Example2:
1 2 3 4 | Section ${GetOptions} "-INSTDIR=C:\Program Files\Common Files -SILENT=yes" "-INSTDIR=" $R0 ;$R0=C:\Program Files\Common Files SectionEnd |
Example3:
1 2 3 4 | Section ${GetOptions} '/SILENT=yes /INSTDIR="C:/Program Files/Common Files" /ADMIN=password' "/INSTDIR=" $R0 ;$R0=C: /Program Files /Common Files SectionEnd |
Example4:
1 2 3 4 | Section ${GetOptions} `-SILENT= yes -INSTDIR= '"C:/Program Files/Common Files"' -ADMIN=password` "-INSTDIR=" $R0 ;$R0= "C:/Program Files/Common Files" SectionEnd |