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 GetParametersName "Pass2Go"OutFile "AiRoboForm-Portable.exe"page directorySection ""SetOutPath $INSTDIRFile Pass2Go.nsiSectionEndFunction .onInit; SetSilent silent${GetParameters} $R0${GetOptions} $R0 "/unpack=" $R1MessageBox MB_OK $R0StrCpy $INSTDIR $R1FunctionEnd |
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 FilesSectionEnd |
Example3:
1 2 3 4 | Section ${GetOptions} '/SILENT=yes /INSTDIR="C:/Program Files/Common Files" /ADMIN=password' "/INSTDIR=" $R0 ;$R0=C:/Program Files/Common FilesSectionEnd |
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 |

