当前位置:网站首页>II Simple NSIS installation package
II Simple NSIS installation package
2022-07-05 07:34:00 【sukhoi27smk】
New script : The wizard
Let's start with a simple NSIS Installation package start , Just like the front. (NSIS Introduce ) said , Although we have read the user manual , But there is no way to write the installation script , Then our editing tool HM NIS Edit That comes in handy .
open HM NIS Edit, Click menu “ file ”->“ New script : The wizard ”, There will be wizards that let us enter information step by step , Finally, according to our input .nsi Script files , Let's demonstrate step by step :
New script : Script files
Finally, we save the generated script file as MyApp.nsi, Open view script ( Check the items set in the screenshot above with the user manual , You will know the basic structure and basic instruction usage of a complete script file )
; Script generated by the HM NIS Edit Script Wizard.
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "My application"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "My company, Inc."
!define PRODUCT_WEB_SITE "http://www.mycompany.com"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
; MUI 1.67 compatible ------
!include "MUI.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "E:\ZZL\ADWeb\ Installation package production \Licence.txt"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "SimpChinese"
; MUI end ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\My application"
ShowInstDetails show
ShowUnInstDetails show
Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite try
File "E:\ZZL\ADWeb\ Installation package production \Release\404.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\Default.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\Error.aspx"
SetOutPath "$INSTDIR\Images"
File "E:\ZZL\ADWeb\ Installation package production \Release\Images\1_close.png"
File "E:\ZZL\ADWeb\ Installation package production \Release\Images\1_open.png"
File "E:\ZZL\ADWeb\ Installation package production \Release\Images\add.png"
SetOutPath "$INSTDIR\Scripts"
File "E:\ZZL\ADWeb\ Installation package production \Release\Scripts\CommonScript.js"
SetOutPath "$INSTDIR\SystemLog"
File "E:\ZZL\ADWeb\ Installation package production \Release\SystemLog\LogStatisticsDetail.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\SystemLog\SystemLogList.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\SystemLog\SystemLogStatistics.aspx"
SetOutPath "$INSTDIR"
File "E:\ZZL\ADWeb\ Installation package production \Release\Web.config"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.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}" "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
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) Successfully removed from your computer ."
FunctionEnd
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 " You really want to completely remove $(^Name) , It and all its components ?" IDYES +2
Abort
FunctionEnd
Section Uninstall
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\Web.config"
Delete "$INSTDIR\SystemLog\SystemLogStatistics.aspx"
Delete "$INSTDIR\SystemLog\SystemLogList.aspx"
Delete "$INSTDIR\SystemLog\LogStatisticsDetail.aspx"
Delete "$INSTDIR\Scripts\CommonScript.js"
Delete "$INSTDIR\Images\add.png"
Delete "$INSTDIR\Images\1_open.png"
Delete "$INSTDIR\Images\1_close.png"
Delete "$INSTDIR\Error.aspx"
Delete "$INSTDIR\Default.aspx"
Delete "$INSTDIR\404.aspx"
RMDir "$INSTDIR\SystemLog"
RMDir "$INSTDIR\Scripts"
RMDir "$INSTDIR\Images"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
SetAutoClose true
SectionEnd
It is worth noting that , From the third step of the new script wizard, we choose... By default “ modern ”, The corresponding script introduces NSIS Modern user interface header files (!include "MUI.nsh"), The corresponding installation page is marked with !insertmacro MUI_PAGE_*** start ( Such as : The welcome page !insertmacro MUI_PAGE_WELCOME), For detailed instructions, please see NSIS Modern User Interface.
Installation package : Modern interface
Let's see the effect of the installation package , stay HM NIS Edit Interface , Click menu “NSIS”->“ Compile and run ”, The output window will show the compilation process , If there is no error , It will directly execute the compilation Setup.exe, The installation screenshot is as follows :
From the screenshot above, we can see that our installation packages share 5 A user interface , This corresponds to the script file :
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "E:\ZZL\ADWeb\ Installation package production \Licence.txt"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
among “ Installation record page ” The instructions in the installation section will be actually executed , These instructions can extract files and read , Read and write registry 、INI Documents or ordinary documents , perform Powershell Script , Create directory , Create shortcuts and so on . If an installer has multiple components , Each component has its own code block , When the user chooses to install this component , Then the installer will execute the corresponding code , Then each component needs to correspond to a section , Specific information about optional components will be introduced in later chapters . We currently have only one installation section , Is to put the deployment package file into the installation directory :
Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite try
File "E:\ZZL\ADWeb\ Installation package production \Release\404.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\Default.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\Error.aspx"
SetOutPath "$INSTDIR\Images"
File "E:\ZZL\ADWeb\ Installation package production \Release\Images\1_close.png"
File "E:\ZZL\ADWeb\ Installation package production \Release\Images\1_open.png"
File "E:\ZZL\ADWeb\ Installation package production \Release\Images\add.png"
Sleep 20000
SetOutPath "$INSTDIR\Scripts"
File "E:\ZZL\ADWeb\ Installation package production \Release\Scripts\CommonScript.js"
SetOutPath "$INSTDIR\SystemLog"
File "E:\ZZL\ADWeb\ Installation package production \Release\SystemLog\LogStatisticsDetail.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\SystemLog\SystemLogList.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\SystemLog\SystemLogStatistics.aspx"
SetOutPath "$INSTDIR"
File "E:\ZZL\ADWeb\ Installation package production \Release\Web.config"
SectionEnd
The information about the interface is set in the script wizard ( Such as application name 、 edition 、 company 、 Icon 、 Authorization information 、 Language, etc. ), It can be modified in the script :
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "My application"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "My company, Inc."
!define PRODUCT_WEB_SITE "http://www.mycompany.com"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
; MUI 1.67 compatible ------
!include "MUI.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
There is also some information about the installation package itself ( Such as : name 、 Default installation path 、 Generate installation package name 、 Whether to display installation details, etc ):
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\ADWebManager"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
BrandingText " MyCompany Ltd."
Pay attention to add a line of command BrandingText " Prolliance Ltd.", In this way, the user installation interface is not NSIS The information of , The comparison is as follows :
Modify the script : Standard interface
We use HM NIS Edit The wizard of created with “ Modern interface ” Installation package , The script file introduces NSIS Modern user interface header files (!include "MUI.nsh"), Now let's not introduce additional header files , Change to NSIS Try the standard interface , As we can see from the user manual , We can go through Page command ( Or more advanced settings such as PageEx). Our modified script file is as follows :
; Script generated by the HM NIS Edit Script Wizard.
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "My application"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "My company, Inc."
!define PRODUCT_WEB_SITE "http://www.mycompany.com"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
; pages
PageEx license
LicenseText " License page "
LicenseData "E:\ZZL\ADWeb\ Installation package production \Licence.txt"
;LicenseForceSelection
PageExEnd
PageEx directory
DirText " Directory selection page " " Destination folder " " Browse ..."
PageExEnd
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
; MUI end ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "$PROGRAMFILES\My application"
ShowInstDetails show
ShowUnInstDetails show
BrandingText " MyCompany Ltd."
Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite try
File "E:\ZZL\ADWeb\ Installation package production \Release\404.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\Default.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\Error.aspx"
SetOutPath "$INSTDIR\Images"
File "E:\ZZL\ADWeb\ Installation package production \Release\Images\1_close.png"
File "E:\ZZL\ADWeb\ Installation package production \Release\Images\1_open.png"
File "E:\ZZL\ADWeb\ Installation package production \Release\Images\add.png"
Sleep 20000
SetOutPath "$INSTDIR\Scripts"
File "E:\ZZL\ADWeb\ Installation package production \Release\Scripts\CommonScript.js"
SetOutPath "$INSTDIR\SystemLog"
File "E:\ZZL\ADWeb\ Installation package production \Release\SystemLog\LogStatisticsDetail.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\SystemLog\SystemLogList.aspx"
File "E:\ZZL\ADWeb\ Installation package production \Release\SystemLog\SystemLogStatistics.aspx"
SetOutPath "$INSTDIR"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.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}" "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
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) Successfully removed from your computer ."
FunctionEnd
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 " You really want to completely remove $(^Name) , It and all its components ?" IDYES +2
Abort
FunctionEnd
Section Uninstall
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\Web.config"
Delete "$INSTDIR\SystemLog\SystemLogStatistics.aspx"
Delete "$INSTDIR\SystemLog\SystemLogList.aspx"
Delete "$INSTDIR\SystemLog\LogStatisticsDetail.aspx"
Delete "$INSTDIR\Scripts\CommonScript.js"
Delete "$INSTDIR\Images\add.png"
Delete "$INSTDIR\Images\1_open.png"
Delete "$INSTDIR\Images\1_close.png"
Delete "$INSTDIR\Error.aspx"
Delete "$INSTDIR\Default.aspx"
Delete "$INSTDIR\404.aspx"
RMDir "$INSTDIR\SystemLog"
RMDir "$INSTDIR\Scripts"
RMDir "$INSTDIR\Images"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
SetAutoClose true
SectionEnd
Installation package : Standard interface
Now let's see the effect of the installation package generated by the script of the standard interface , After implementation HM NIS Edit Interface , Click menu “NSIS”->“ Compile and run ”, The output window will show the compilation process , If there is no error , It will directly execute the compilation Setup.exe, The installation screenshot is as follows :
Is it compared “ Modern user interface ”, The standard interface will be ugly , and NSIS The built-in standard installation interface is not welcome 、 Complete the interface ( Only License 、 Catalog selection 、 Components 、 Installation record page ) , in addition “ The previous step ”、“ next step ”、“ Cancel ” And other buttons require additional language pack files to load , Not as good as “ Modern user interface ” Just one instruction (!insertmacro MUI_LANGUAGE "SimpChinese") To specify the language , So next we will adopt “ Modern user interface ” To make the installation package , Of course, the icons on these interfaces , Text anywhere can be customized .
The following chapters are written with Application in practice As an example , Then the example is expanded to illustrate the customization of the page 、PowerShell Command invocation 、SQL Server Database access 、Web Application deployment 、 Failed rollback and the execution of the uninstaller, etc .
边栏推荐
- 2022 PMP project management examination agile knowledge points (7)
- Unforgettable summary of 2021
- 611. 有效三角形的个数
- DataGrid offline installation of database driver
- Database SQL practice 3. Find the current salary details of the current leaders of each department and their corresponding department number Dept_ no
- Delayqueue usage and scenarios of delay queue
- repo. conda. An example of COM path error
- 2022年PMP项目管理考试敏捷知识点(7)
- Using GEE plug-in in QGIS
- [idea] efficient plug-in save actions to improve your work efficiency
猜你喜欢
剑指 Offer 56 数组中数字出现的次数(异或)
HDU1232 畅通工程(并查集)
arcgis_ spatialjoin
Thunderbird tutorial \ easy to use mail client
[idea] efficient plug-in save actions to improve your work efficiency
Target detection series - detailed explanation of the principle of fast r-cnn
Ue5 hot update - remote server automatic download and version detection (simplehotupdate)
Graduation thesis project local deployment practice
DelayQueue延迟队列的使用和场景
Daily Practice:Codeforces Round #794 (Div. 2)(A~D)
随机推荐
玩转gRPC—深入概念与原理
Explanation of parallel search set theory and code implementation
Detailed explanation of miracast Technology (I): Wi Fi display
Jenkins reported an error. Illegal character: '\ufeff'. Class, interface or enum are required
Pit record of Chmod 2 options in deepin
2022 PMP project management examination agile knowledge points (7)
Oracle-触发器和程序包
How to modify the file path of Jupiter notebook under miniconda
公安基础知识--fb
ORACLE CREATE SEQUENCE,ALTER SEQUENCE,DROP SEQUENCE
What is soda?
Target detection series - detailed explanation of the principle of fast r-cnn
Typecho adds Baidu collection (automatic API submission plug-in and crawler protocol)
NPM and package common commands
list. files: List the Files in a Directory/Folder
Professional knowledge of public security -- teacher bilitong
[neo4j] common operations of neo4j cypher and py2neo
Microservice registry Nacos introduction
Simple operation of nixie tube (keil5)
And play the little chestnut of dynamic agent