NSIS安装脚本
NSIS安裝腳本
http://www.cnblogs.com/passingcloudss/archive/2011/10/21/2220663.html
${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
總結
- 上一篇: 如何关闭Windows XP/Vista
- 下一篇: NSIS安装制作程序