NSIS对文件夹程序封装exe文件
; 该脚本使用 HM VNISEdit 脚本编辑器向导产生
; 安装程序初始定义常量
!define PRODUCT_NAME "{名字}"
!define PRODUCT_VERSION "{日期}"
!define PRODUCT_PUBLISHER "{作者}"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\{名字}.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
SetCompressor lzma
; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
!include "MUI.nsh"
; MUI 预定义常量
!define MUI_ABORTWARNING
!define MUI_ICON "{ico肖像全路径}"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 安装目录选择页面
;!insertmacro MUI_PAGE_DIRECTORY
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装完成页面
!define MUI_FINISHPAGE_RUN "$INSTDIR\bin\{名字}.exe"
!insertmacro MUI_PAGE_FINISH
; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"
; 安装预释放文件
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 现代界面定义结束 ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "{输出exe文件的名字}.exe"
InstallDir "{安装路径}"
InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails show
ShowUnInstDetails show
RequestExecutionLevel admin
BrandingText "{名字}"
Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File /r "{文件夹路径}\*.*"
Sleep 200
CreateDirectory "$SMPROGRAMS\{名字}"
Sleep 200
CreateShortCut "$SMPROGRAMS\{名字}\{名字}.lnk" "$INSTDIR\bin\{名字}.exe"
Sleep 200
CreateShortCut "$DESKTOP\{名字}.lnk" "$INSTDIR\bin\{名字}.exe"
File "{文件夹运行程序路径}.exe"
SectionEnd
Section -AdditionalIcons
Sleep 200
CreateShortCut "$SMPROGRAMS\{名字}\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
Sleep 200
WriteUninstaller "$INSTDIR\uninst.exe"
Delete "$INSTDIR\{名字}.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\bin\{名字}.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\bin\{名字}.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
WriteRegStr HKCR "eVIAS" "" "eVIASProtocol"
WriteRegStr HKCR "eVIAS" "URL Protocol" "$INSTDIR\Bin\{名字}.exe"
WriteRegStr HKCR "eVIAS\DefaultIcon" "" "$INSTDIR\Bin\{名字}.exe,1"
WriteRegStr HKCR "eVIAS\shell\open\command" "" "$INSTDIR\Bin\{名字}.exe %1"
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" "EnableLUA" "dword:00000000"
SectionEnd
/******************************
* 以下是安装程序的卸载部分 *
******************************/
Section Uninstall
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\{名字}.exe"
Delete "$SMPROGRAMS\{名字}\Uninstall.lnk"
Delete "$DESKTOP\{名字}.lnk"
Delete "$SMPROGRAMS\{名字}\{名字}.lnk"
RMDir "$SMPROGRAMS\{名字}"
RMDir /r "$INSTDIR\temp"
RMDir /r "$INSTDIR\db"
RMDir /r "$INSTDIR\data"
RMDir /r "$INSTDIR\conf"
RMDir /r "$INSTDIR\bin"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 $(^Name) ,及其所有的组件?" IDYES +2
Abort
FunctionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
FunctionEnd