NSIS:使用PassDialog插件实现密码安装功能

1、在相应位置(比如 欢迎页面 后面)加入以下代码:

Page Custom PasswordPageShow PasswordPageLeave
 !define MUI_PAGE_CUSTOMFUNCTION_SHOW ComponentsPageShow
 ## Password is
 !define Password "123"
 ## Control ID's
 !define IDC_PASSWORD 123

2、在 Section 区段后面加入以下代码:

## Displays the password dialog
 Function PasswordPageShow

 !insertmacro MUI_HEADER_TEXT "输入密码" "程序需要一个正确的安装密码才能继续。"

 PassDialog::InitDialog /NOUNLOAD Password /HEADINGTEXT "您可以致电0769-3838438或登陆www.bearpc.net索取密码。" /GROUPTEXT "密码输入框"
 Pop $R0 # Page HWND

 GetDlgItem $R1 $R0 ${IDC_PASSWORD}
 SendMessage $R1 ${EM_SETPASSWORDCHAR} 178 0

 PassDialog::Show

 FunctionEnd

 ## Validate password
 Function PasswordPageLeave

 ## Pop password from stack
 Pop $R0

 ## A bit of validation
 StrCmp $R0 '${Password}' +3
 MessageBox MB_OK|MB_ICONEXCLAMATION "密码错误!请输入正确的安装密码!"
 Abort

 ## Display the password
 MessageBox MB_OK|MB_ICONINFORMATION "密码正确,点击“确定”继续!"

 FunctionEnd

 Function ComponentsPageShow

 ## Disable the Back button
 GetDlgItem $R0 $HWNDPARENT 3
 EnableWindow $R0 0

 FunctionEnd
© 版权声明
THE END
喜欢就支持一下吧
点赞16 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容