当前位置:网站首页>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.06.27_ One question per day
- Course learning accumulation ppt
- (tool use) how to make the system automatically match and associate to database fields by importing MySQL from idea and writing SQL statements
- 纯碱是做什么的?
- The folder directly enters CMD mode, with the same folder location
- Shadowless cloud desktop - online computer
- Set theory of Discrete Mathematics (I)
- Detailed explanation of miracast Technology (I): Wi Fi display
- Apple system shortcut key usage
- Basic operation of external interrupt (keil5)
猜你喜欢
How to delete the virus of inserting USB flash disk copy of shortcut to
Ugnx12.0 initialization crash, initialization error (-15)
DataGrid offline installation of database driver
行测--资料分析--fb--高照老师
What is deep learning?
HDU1232 畅通工程(并查集)
Oracle-触发器和程序包
611. 有效三角形的个数
What if the DataGrid cannot see the table after connecting to the database
How to deal with excessive memory occupation of idea and Google browser
随机推荐
Brief description of inux camera (Mipi interface)
【idea】Could not autowire. No beans of xxx type found
Basic series of SHEL script (III) for while loop
Oracle code use
[idea] common shortcut keys
Hdu1232 unimpeded project (and collection)
Anaconda navigator click open no response, can not start error prompt attributeerror: 'STR' object has no attribute 'get‘
Today, share the wonderful and beautiful theme of idea + website address
苏打粉是什么?
Close of office 365 reading
[tf1] save and load parameters
CADD课程学习(5)-- 构建靶点已知的化合结构(ChemDraw)
Implementation of one-dimensional convolutional neural network CNN based on FPGA (VIII) implementation of activation layer
Word import literature -mendeley
Simple operation of nixie tube (keil5)
Ggplot2 drawing learning notes in R
Target detection series - detailed explanation of the principle of fast r-cnn
Thunderbird tutorial \ easy to use mail client
HDU1232 畅通工程(并查集)
golang定时器使用踩的坑:定时器每天执行一次