!include "MUI2.nsh"
Name "Fifth Installer"
OutFile "fifthinstaller.exe"
InstallDir " $PROGRAMFILES \MyFifthInstaller"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section ""
SetOutPath $INSTDIR
File "C:\Windows\system32\notepad.exe"
WriteUninstaller " $INSTDIR \uninstall.exe"
SectionEnd
Section "Uninstall"
Delete $INSTDIR \uninstall.exe
Delete $INSTDIR \notepad.exe
RMDir $INSTDIR
SectionEnd
!include "MUI2.nsh"
插入 MUI2.nsh 檔案,就好像它是我們指令碼的一部分一樣。所需的宏已在 MUI2.nsh 檔案中定義。
!insertmacro ......
作為 Page 或 UninstPage 命令的替代,插入帶有宏的所需頁面。
!insertmacro MUI_LANGUAGE "English"
使用此宏可以插入英文文字.對於中文,需要指定語言為“SimpChinese”
第四個安裝程式重灌
我們當然希望將第二部分中新增的對話方塊也使用現代使用者介面來實現。
下面開始:
!include "MUI2.nsh"
Name "Sixth Installer"
!define INSTALLATIONNAME "MySixthInstaller"
OutFile "MySixthInstaller.exe"
InstallDir $PROGRAMFILES\${INSTALLATIONNAME}
Page custom getUsername nsDialogsPageLeave
!insertmacro MUI_PAGE_LICENSE "license.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "SimpChinese"
LangString PAGE_TITLE ${LANG_SimpChinese} "自定義頁面示例"
LangString PAGE_SUBTITLE ${LANG_SimpChinese} "請輸入使用者名稱或密碼"
Var Text
Var Dialog
Function ".onInit"
InitPluginsDir
#此處預釋放某些安裝必須的資源或者檔案....
#File /oname=$PLUGINSDIR\name.ini "name.ini"
FunctionEnd
Function getUsername
!insertmacro MUI_HEADER_TEXT $(PAGE_TITLE) $(PAGE_SUBTITLE)
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 14u 19% 12u "使用者名稱或密碼"
${NSD_CreateText} 20% 13u 100% 15u ""
Pop $Text
nsDialogs::Show
FunctionEnd
Function nsDialogsPageLeave
${NSD_GetText} $Text $0
MessageBox MB_OK " 使用者名稱或密碼是: $0 "
FunctionEnd
Section ""
SetOutPath $INSTDIR
File C:\Windows\system32\notepad.exe
WriteUninstaller $INSTDIR\uninstall.exe
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${INSTALLATIONNAME}" "DisplayName" "Forth Installer"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${INSTALLATIONNAME}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${INSTALLATIONNAME}" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${INSTALLATIONNAME}" "NoRepair" 1
SectionEnd
Section "Sample Text File"
;File "license.txt"
SectionEnd
Section /o "Another Sample Text File"
;非必要元件
; File "license2.txt"
SectionEnd
Section "Start Menu Shortcuts"
CreateDirectory "$SMPROGRAMS\${INSTALLATIONNAME}"
CreateShortCut "$SMPROGRAMS\${INSTALLATIONNAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\${INSTALLATIONNAME}\notepad.lnk" "$INSTDIR\notepad.exe" "" "$INSTDIR\notepad.exe" 0
SectionEnd
Section "Uninstall"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${INSTALLATIONNAME}"
Delete $INSTDIR\uninstall.exe
Delete $INSTDIR\notepad.exe
Delete $INSTDIR\license.txt
Delete $INSTDIR\license2.txt
RMDir $INSTDIR
Delete "$SMPROGRAMS\${INSTALLATIONNAME}\*.*"
RMDir "$SMPROGRAMS\${INSTALLATIONNAME}"
SectionEnd
NSIS Modern UI 2.0 安裝程式
!insertmacro MUI_HEADER_TEXT $(PAGE_TITLE) $(PAGE_SUBTITLE)
這行程式碼定義了自定義頁面的標題欄文字內容。如指令碼所示,這並不需要其他特殊的 !insertmacro 指令。標題和副標題內容使用 LangString 指令定義即可。