当前位置: > 部署 >

NSIS:卸载加密码示例

  • 部署
  • 2014-03-14 15:53

最近有几个同学问我关于卸载时加密码的问题,其实很简单,懂点基础就可以根据安装加密码那篇文章http://www.flighty.cn/html/bushu/20100928_99.html来改写一下了,现在我把这个发出来,希望能够帮助到大家,也希望大家能够常来帮我点点广告呵。

 

直接上代码:(如果编译失败可能是因为缺少插件,请下载NSIS集成增强版http://www.flighty.cn/html/soft/20100429_76.html)

/*
卸载加密码示例 by 少轻狂
轻狂志http://www.flighty.cn/html/bushu/20140314_226.html
*/

!define PRODUCT_NAME "卸载加密码示例"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "My company, Inc."
!define PRODUCT_WEB_SITE "http://www.flighty.cn"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\AppMainExe.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

SetCompressor lzma
SetFont "tahoma" 8
RequestExecutionLevel admin

!include "MUI2.nsh"

!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
;卸载密码
!define Password "123"

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

;卸载密码输入页面
UninstPage Custom un.PasswordPageShow un.PasswordPageLeave
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

!insertmacro MUI_LANGUAGE "SimpChinese"

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\卸载加密码示例"
InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails show
ShowUnInstDetails show

Section "MainSection" SEC01
  SetOutPath "$INSTDIR"
  SetOverwrite ifnewer
  CreateDirectory "$SMPROGRAMS\卸载加密码示例"
SectionEnd

Section -AdditionalIcons
  CreateDirectory "$SMPROGRAMS\卸载加密码示例"
  CreateShortCut "$SMPROGRAMS\卸载加密码示例\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\AppMainExe.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\AppMainExe.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

/******************************
 *  以下是安装程序的卸载部分  *
 ******************************/

Section Uninstall
  Delete "$INSTDIR\uninst.exe"

  Delete "$SMPROGRAMS\卸载加密码示例\Uninstall.lnk"

  RMDir "$SMPROGRAMS\卸载加密码示例"

  RMDir "$INSTDIR"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  SetAutoClose true
SectionEnd

Function un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
FunctionEnd

;显示密码对话框
Function un.PasswordPageShow
  !insertmacro MUI_HEADER_TEXT "输入密码" "卸载程序需要输入一个正确的密码以防止误操作。"
  PassDialog::InitDialog /NOUNLOAD Password /HEADINGTEXT "少轻狂提示:卸载密码是123。" /GROUPTEXT "密码输入框"
  Pop $R0
  SendMessage $R1 ${EM_SETPASSWORDCHAR} 178 0
  PassDialog::Show
FunctionEnd

;验证密码
Function un.PasswordPageLeave
  ;从堆栈取出密码
  Pop $R0
  ;密码错误
  StrCmp $R0 '${Password}' +3
  MessageBox MB_OK|MB_ICONEXCLAMATION "密码输入错误!请输入正确的卸载密码!"
  Abort
FunctionEnd

 

猜你喜欢

最新评论

说点什么吧
  • 全部评论(0