NSIS 入门教程 (二)
Name "Second Installer"
OutFile "secondinstaller.exe"
InstallDir $PROGRAMFILES\MySecondInstaller
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
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
除了将名称更改为“"Second Installer(第二个安装程序)”之外,我们还添加了三条指令:
Page license
命令。LicenseData
命令指定包含许可条款的文件( .txt 或 .rtf 格式)。LicenseText
命令自定义显示在许可文本上方的文本!include nsdialogs.nsh
Name "Third Installer"
OutFile "thirdinstaller.exe"
InstallDir $PROGRAMFILES\MyThirdInstaller
Page license
Page custom getUsername nsDialogsPageLeave
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
LicenseData "NSIS脚本文件.nsi"
Var Text
Var Dialog
Function ".onInit"
InitPluginsDir
#此处预释放某些安装必需的资源或者文件....
#File /oname=$PLUGINSDIR\name.ini "name.ini"
FunctionEnd
Function getUsername
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
SectionEnd
Section "Uninstall"
Delete $INSTDIR\uninstall.exe
Delete $INSTDIR\notepad.exe
RMDir $INSTDIR
SectionEnd
!include nsdialogs.nsh
Name " fourth Installer"
OutFile "fourthinstaller.exe"
InstallDir $PROGRAMFILES\MyFourthInstaller
!define INSTALLATIONNAME "MyForthInstaller"
Page license
Page custom getUsername nsDialogsPageLeave
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
LicenseData "license.txt"
Var Text
Var Dialog
Function ".onInit"
InitPluginsDir
#此处预释放某些安装必须的资源或者文件....
#File /oname=$PLUGINSDIR\name.ini "name.ini"
FunctionEnd
Function getUsername
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
本文来自博客园,作者:水晶石,转载请注明原文链接:https://www.cnblogs.com/NSIS/p/18262587