用PassDialog插件实现密码安装功能
优质
小牛编辑
138浏览
2023-12-01
有时,出于特殊的需求,我们要给安装程序加一个密码,只有输入了正确的密码才可以继续安装。比如:
1、在相应位置(比如 欢迎页面 后面)加入以下代码:
## Pages Page Custom PasswordPageShow PasswordPageLeave !define MUI_PAGE_CUSTOMFUNCTION_SHOW ComponentsPageShow !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_INSTFILES ## 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 "您可以致电053283601988索取密码。" /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