当前位置:网站首页>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
SectionEndIt 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_FINISHamong “ 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"
SectionEndThe 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
SectionEndInstallation 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 .
边栏推荐
- arcpy. SpatialJoin_ Analysis spatial connection analysis
- 公安基础知识--fb
- Set theory of Discrete Mathematics (I)
- The number of occurrences of numbers in the offer 56 array (XOR)
- GBK error in web page Chinese display (print, etc.), solution
- Idea to view the source code of jar package and some shortcut keys (necessary for reading the source code)
- UNIX commands often used in work
- HDU1231 最大连续子序列(分治or动规or双指针)
- String alignment method, self use, synthesis, newrlcjust
- Reading literature sorting 20220104
猜你喜欢

The problem of configuring opencv in qt5.13.2 is solved in detail

Ue5 hot update - remote server automatic download and version detection (simplehotupdate)

借助 Navicat for MySQL 软件 把 不同或者相同数据库链接中的某数据库表数据 复制到 另一个数据库表中

行测--资料分析--fb--高照老师

Graduation thesis project local deployment practice

How to modify the file path of Jupiter notebook under miniconda

CADD课程学习(6)-- 获得已有的虚拟化合物库(Drugbank、ZINC)

Set theory of Discrete Mathematics (I)

With the help of Navicat for MySQL software, the data of a database table in different or the same database link is copied to another database table

Thunderbird tutorial \ easy to use mail client
随机推荐
DelayQueue延迟队列的使用和场景
纯碱是做什么的?
Reading literature sorting 20220104
M2DGR 多源多场景 地面机器人SLAM数据集
Simple use of timeunit
Basic operation of external interrupt (keil5)
Explanation of parallel search set theory and code implementation
Target detection series - detailed explanation of the principle of fast r-cnn
大学生活的自我总结-大一
Differences between pycharm and idle and process -- join() in vs Code
Apple modify system shortcut key
氫氧化鈉是什麼?
Ggplot2 drawing learning notes in R
I 用c l 栈与队列的相互实现
How to delete the virus of inserting USB flash disk copy of shortcut to
ImportError: No module named ‘Tkinter‘
Web page Chinese display (print, etc.) GBK error, solution, software
Anaconda pyhton multi version switching
arcpy. SpatialJoin_ Analysis spatial connection analysis
How to deal with excessive memory occupation of idea and Google browser