GetParameters
用途:获取命令行参数
语法:${GetParameters} $var
我们需要先引用头文件:
!include "FileFunc.nsh"
然后指定静默参数要运行的函数体:
${If} $R0 == "/I"
Call Install
Quit
${ElseIf} $R0 == "/U"
Call Uninstall
Quit
${EndIf}
完整示例:
/*
利用nsDialogs CreateButton创建2个按钮。
加入静默参数 /I用于安装 /U用于卸载。
*/
!include nsDialogs.nsh
!include "FileFunc.nsh"
XPStyle on
LoadLanguageFile "${NSISDIR}\Contrib\Language files\SimpChinese.nlf"
Caption "自定义静默参数示例"
OutFile "自定义静默参数示例.exe"
!insertmacro GetParameters
Page custom nsDialogsPage
Var In
Var Un
Section "NSISFANS"
SectionEnd
Function .onInit
${GetParameters} $R0
${If} $R0 == "/I"
Call Install
Quit
${ElseIf} $R0 == "/U"
Call Uninstall
Quit
${EndIf}
FunctionEnd
Function nsDialogsPage
nsDialogs::Create 1018
${NSD_CreateButton} 120 50 163 20u "静默安装(I)"
Pop $In
${NSD_OnClick} $In Install
${NSD_CreateButton} 120 100 163 20u "静默卸载(U)"
Pop $Un
${NSD_OnClick} $Un Uninstall
nsDialogs::Show
FunctionEnd
Function Install
MessageBox MB_OK "成功使用参数I安装啦!"
FunctionEnd
Function Uninstall
MessageBox MB_OK "成功使用参数I卸载啦!"
FunctionEnd
© 版权声明
THE END
暂无评论内容