NSIS 入门教程 (三)
!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 指令定义即可。
本文来自博客园,作者:水晶石,转载请注明原文链接:https://www.cnblogs.com/NSIS/p/18263279