Windows 下免費製作軟體安裝包工具介紹-nullsoft scriptable install systen(NSIS) (02)
Windows 下免費製作軟體安裝包工具介紹-nullsoft
scriptable install systen(NSIS) (02)
使用HM VNISEdit產生NSI檔基本框架
; 該指令檔使用 HM VNISEdit 指令檔編輯器精靈產生
; 安裝程式初始定義常量
!define PRODUCT_NAME "軟體名稱"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "公司名稱"
!define PRODUCT_WEB_SITE "公司網址"
!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 /SOLID lzma
; ------ MUI 現代介面定義 (1.67 版本以上相容) ------
!include "MUI.nsh"
; MUI 預定義常量
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; 語言選擇視窗常量設定
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
; 歡迎頁面
!insertmacro MUI_PAGE_WELCOME
; 授權合約頁面
;!insertmacro MUI_PAGE_LICENSE "c:\path\to\licence\YourSoftwareLicence.txt"
; 安裝資料夾選擇頁面
!insertmacro MUI_PAGE_DIRECTORY
; 安裝過程頁面
!insertmacro MUI_PAGE_INSTFILES
; 安裝完成頁面
!define MUI_FINISHPAGE_RUN "$INSTDIR\ 主執行檔名.exe "
!insertmacro MUI_PAGE_FINISH
; 安裝卸載過程頁面
!insertmacro MUI_UNPAGE_INSTFILES
; 安裝介麵包含的語言設定
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"
; 安裝預釋放檔案
!insertmacro MUI_RESERVEFILE_LANGDLL
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 現代介面定義結束 ------
ReserveFile "${NSISDIR}\Plugins\splash.dll"
;ReserveFile "c:\path\to\Splash\YourSplash.bmp"
;ReserveFile "c:\path\to\Splash\YourSplashSound.wav"
ReserveFile "${NSISDIR}\Plugins\system.dll"
;ReserveFile "c:\path\to\YourMIDI.mid"
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
File "C:\Users\admin\Desktop\test\ 元件.dll"
CreateDirectory "$SMPROGRAMS\ 軟體目錄"
CreateShortCut "$SMPROGRAMS\ 軟體目錄\捷徑檔名.lnk" "$INSTDIR\主執行檔名.exe "
CreateShortCut "$DESKTOP\ 捷徑檔名.lnk" "$INSTDIR\ 主執行檔名.exe"
SetOutPath "$INSTDIR\en"
File "C:\Users\admin\Desktop\test\en\ 元件.dll"
SetOutPath "$INSTDIR"
File "C:\Users\admin\Desktop\test\ 元件.dll"
File "C:\Users\admin\Desktop\test\ 元件.dll"
File "C:\Users\admin\Desktop\test\ 元件.dll"
File "C:\Users\admin\Desktop\test\ 元件.dll"
File "C:\Users\admin\Desktop\test\ 元件.dll"
File "C:\Users\admin\Desktop\test\ 元件.dll"
File "C:\Users\admin\Desktop\test\ 元件.dll"
File "C:\Users\admin\Desktop\test\ 主執行檔名exe"
SetOutPath "$INSTDIR\zh-CN"
File "C:\Users\admin\Desktop\test\zh-CN\ 元件.dll"
SetOutPath "$INSTDIR\zh-TW"
File "C:\Users\admin\Desktop\test\zh-TW\ 元件.dll"
SectionEnd
Section -AdditionalIcons
SetOutPath $INSTDIR
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\ 目錄\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\ 目錄\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\ 主程式檔名.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\ 主執行檔名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
#-- 依 NSIS 指令檔編輯規則,所有 Function 區段必須放置在 Section 區段之後編寫,以避免安裝程式出現未可預知的問題。--#
Function .onInit
InitPluginsDir
;File "/oname=$PLUGINSDIR\Splash_YourSplash.bmp" "c:\path\to\Splash\YourSplash.bmp"
;File "/oname=$PLUGINSDIR\Splash_YourSplash.wav" "c:\path\to\Splash\YourSplashSound.wav"
; 使用閃屏外掛程式顯示閃屏
splash::show 1000 "$PLUGINSDIR\Splash_YourSplash"
Pop $0 ; $0 返回 '1' 表示使用者提前關閉閃屏, 返回 '0' 表示閃屏正常結束, 返回 '-1' 表示閃屏顯示出錯
;File "/oname=$PLUGINSDIR\bgm_YourMIDI.mid" "c:\path\to\YourMIDI.mid"
; 開啟音樂檔案
System::Call "winmm.dll::mciSendString(t 'OPEN $PLUGINSDIR\bgm_YourMIDI.mid TYPE SEQUENCER ALIAS BGMUSIC', t .r0, i 130, i 0)"
; 開始播放音樂檔案
System::Call "winmm.dll::mciSendString(t 'PLAY BGMUSIC NOTIFY', t .r0, i 130, i 0)"
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
Function .onGUIEnd
; 停止播放音樂檔案
System::Call "winmm.dll::mciSendString(t 'STOP BGMUSIC',t .r0,i 130,i 0)"
; 關閉音樂檔案
System::Call "winmm.dll::mciSendString(t 'CLOSE BGMUSIC',t .r0,i 130,i 0)"
FunctionEnd
/******************************
* 以下是安裝程式的卸載部分 *
******************************/
Section Uninstall
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\zh-TW\ 元件.dll"
Delete "$INSTDIR\zh-CN\ 元件.dll"
Delete "$INSTDIR\ 主程式檔名.exe"
Delete "$INSTDIR\ 元件.dll"
Delete "$INSTDIR\ 元件.dll"
Delete "$INSTDIR\ 元件.dll"
Delete "$INSTDIR\ 元件.dll"
Delete "$INSTDIR\ 元件.dll"
Delete "$INSTDIR\ 元件.dll"
Delete "$INSTDIR\ 元件.dll"
Delete "$INSTDIR\en\ 元件.dll"
Delete "$INSTDIR\ 元件.dll"
Delete "$SMPROGRAMS\ 目錄\Uninstall.lnk"
Delete "$SMPROGRAMS\ 目錄\Website.lnk"
Delete "$DESKTOP\ 捷徑.lnk"
Delete "$SMPROGRAMS\ 目錄\捷徑.lnk"
RMDir "$SMPROGRAMS\ 目錄"
RMDir "$INSTDIR\zh-TW"
RMDir "$INSTDIR\zh-CN"
RMDir "$INSTDIR\en"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
#-- 依 NSIS 指令檔編輯規則,所有 Function 區段必須放置在 Section 區段之後編寫,以避免安裝程式出現未可預知的問題。--#
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 " 你確實要完全移除 $(^Name) ,及其所有的元件?" IDYES +2
Abort
FunctionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地從你的電腦移除。"
FunctionEnd