${PRODUCT_NAME}; 安装程序初始定义常量 !define PRODUCT_NAME "软件名" !define PRODUCT_VERSION "1.0" !define PRODUCT_WEB_SITE "http://www.google.com" !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}.exe" !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" !define PRODUCT_UNINST_ROOT_KEY "HKLM" !define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir" SetCompressor /SOLID lzma SetCompressorDictSize 32 ; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------ !include "MUI.nsh" ; MUI 预定义常量 !define MUI_ABORTWARNING ;当用户要关闭安装程序时, 显示一个警告消息框 !define MUI_UNABORTWARNING ;当用户要关闭卸载程序时, 显示一个警告消息框 !define MUI_ICON "install.ico" ;安装程序图标 !define MUI_UNICON "uninst.ico" ;卸载程序图标 !define MUI_FINISHPAGE_NOAUTOCLOSE ;不自动跳到完成页面, 允许用户检查安装记录 !define MUI_UNFINISHPAGE_NOAUTOCLOSE ;不自动跳到完成页面, 允许用户检查卸载记录 !define MUI_WELCOMEFINISHPAGE_BITMAP "welcome.bmp" ;用于欢迎页面和完成页面的位图(推荐尺寸: 164x314 象素). !define MUI_UNWELCOMEFINISHPAGE_BITMAP "welcome.bmp" ;用于卸载页面的位图(推荐尺寸: 164x314 象素). !define MUI_COMPONENTSPAGE_SMALLDESC ;较小的页面底部的描述区域 !define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_INFO "鼠标移到组件上可查看相应说明" ;当没有选择区段时, 显示于描述框中的文本 ; 欢迎页面 !insertmacro MUI_PAGE_WELCOME ; 组件选择页面 !insertmacro MUI_PAGE_COMPONENTS ; 安装目录选择页面 !insertmacro MUI_PAGE_DIRECTORY ; 开始菜单设置页面 var ICONS_GROUP !define MUI_STARTMENUPAGE_NODISABLE !define MUI_STARTMENUPAGE_DEFAULTFOLDER "${PRODUCT_NAME}" !define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}" !define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}" !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}" !insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP ; 安装过程页面 !insertmacro MUI_PAGE_INSTFILES ; 安装完成页面 !define MUI_FINISHPAGE_RUN "$INSTDIR\${PRODUCT_NAME}.exe" !define MUI_FINISHPAGE_RUN_NOTCHECKED ;默认不选中 '运行程序' 复选框 !define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\Readme.txt" !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED ;默认不选中 '自述文件' 复选框 !define MUI_FINISHPAGE_LINK "【欢迎访问作者主页】" !define MUI_FINISHPAGE_LINK_LOCATION "${PRODUCT_WEB_SITE}" !insertmacro MUI_PAGE_FINISH ; 安装卸载过程页面 !insertmacro MUI_UNPAGE_INSTFILES ; 安装界面包含的语言设置 !insertmacro MUI_LANGUAGE "SimpChinese" !insertmacro MUI_LANGUAGE "English" ; 安装预释放文件 !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS ; ------ MUI 现代界面定义结束 ------ Name "${PRODUCT_NAME} ${PRODUCT_VERSION}" OutFile "Setup.exe" InstallDir "$PROGRAMFILES\${PRODUCT_NAME}" InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString" ShowInstDetails hide ;设置是否显示安装详细信息 ShowUnInstDetails hide BrandingText "作者:" Section "!主程序" SEC01 SectionIn RO ;必选组件灰色 SetOutPath "$INSTDIR" SetOverwrite on File "Readme.txt" ; 创建开始菜单快捷方式 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe" CreateDirectory "$SMPROGRAMS\$ICONS_GROUP" CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.exe" !insertmacro MUI_STARTMENU_WRITE_END SectionEnd ; 安装.NET Framework Section "Microsoft .NET Framework 2.0" SEC02 File "DotNet.exe" ExecWait '"DotNet.exe" /q:a /c:"install.exe /q"' SectionEnd Section -AdditionalIcons !insertmacro MUI_STARTMENU_WRITE_BEGIN Application WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}" CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\欢迎访问作者主页.lnk" "$INSTDIR\${PRODUCT_NAME}.url" CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\卸载.lnk" "$INSTDIR\uninst.exe" !insertmacro MUI_STARTMENU_WRITE_END SectionEnd Section -Post WriteUninstaller "$INSTDIR\uninst.exe" WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\${PRODUCT_NAME}.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\${PRODUCT_NAME}.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}" SectionEnd #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--# ; 区段组件描述 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SEC01} "必备组件" !insertmacro MUI_DESCRIPTION_TEXT ${SEC02} "运行主程序必需的框架,如果确认已经安装,则不必勾选" !insertmacro MUI_FUNCTION_DESCRIPTION_END /****************************** * 以下是安装程序的卸载部分 * ******************************/ Section Uninstall !insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP Delete "$INSTDIR\uninst.exe" Delete "$DESKTOP\${PRODUCT_NAME}.lnk" SetShellVarContext current ;当前用户开始菜单 Delete "$SMPROGRAMS\$ICONS_GROUP\卸载.lnk" Delete "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME}.lnk" Delete "$SMPROGRAMS\$ICONS_GROUP\欢迎访问作者主页.lnk" RMDir /r "$SMPROGRAMS\$ICONS_GROUP" SetShellVarContext all ;全部用户开始菜单 Delete "$SMPROGRAMS\$ICONS_GROUP\卸载.lnk" Delete "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME}.lnk" Delete "$SMPROGRAMS\$ICONS_GROUP\欢迎访问作者主页.lnk" RMDir /r "$SMPROGRAMS\$ICONS_GROUP" RMDir /r "$INSTDIR" DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}" SetAutoClose false 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
转自:http://www.cnblogs.com/passingcloudss/archive/2011/10/21/2220663.html
本文版权归 清风行云 和 博客园 共有,欢迎转载!但未经作者同意,必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利!