The first time most people see a NSIS script, they are all blurred.Because the structure of this script at first looks very strange and you can't read it without explaining it.
When writing script commands, it is important to note that commands are written in different paragraphs of the script as required, that is, the order of commands is very important.
Here's a standard, simple script example that uses comments to illustrate what each command does. If you want to quickly compile an installation package, just follow this example one line at a time.
# NSIS Modern User Interface
# about Modern Style interface commands and macro definitions need reference NSIS Catalog\Docs\Modern UI 2\Readme.html Description of this file.
# If you encounter an unknown command, you can get instructions by directly looking at the manual.
# Paragraphs of a script are divided by lines.Different paragraphs can write different commands, focus on them. # Written by Shiroha #-------------------------------- # Includes # Contains the header file you need to use, which follows C Language is the same. !include "MUI2.nsh" # Use Modern Style interface, the next step interface you are most familiar with. !include "LogicLib.nsh" # Logical operator header file.Namely {If} Those. !include "nsProcess.nsh" # Process Control Plug-in Header File.Used to find and force end processes.This plugin can be used in NSIS Official site found download. #-------------------------------- # General # Basic property settings for the installation package. # Properly display all languages (Installer will not work on Windows 95, 98 or ME!) Unicode true # Set to Unicode Mode, so that the interface can display all languages. # Name and file Name "$(STR_ProductName)" # Set the name of the software. OutFile "vnr_translate_patch_1.4.0.0.exe" # Sets the filename of the compilation output. # Default installation folder InstallDir "" # Set the default installation path. # Allow install to root directory AllowRootDirInstall true # Allows the user to select the root directory of the disk at the installation path selection interface. # Request application privileges for Windows Vista RequestExecutionLevel user # Set the user permissions required to install the package, only for Vista Version above.Set to admin Compiled EXE Will have a shield icon. # Show the details by default ShowInstDetails show # Installation details are displayed by default, and text messages output during installation are displayed. #-------------------------------- # Compiler Flags # Compiler options, affecting compression algorithms, and so on. SetCompressor lzma # Use LZMA Compression algorithm, compression quality is better. SetDateSave off # Without saving the file date, the post-installation file date is newly generated. #-------------------------------- # Interface Settings # Interface options, modify some elements on the interface. # The icon for the installer !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\nsis3-install-alt.ico" # The icon file used by the installation package. MUI_*Macros at the beginning are defined in MUI2.nsh File, please check Modern UI 2 Description. # Sets the text that is shown at the bottom of the install window BrandingText "Provided by Shiroha" # Set the text on the dividing line. # Bitmap for the Welcome page and the Finish page !define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\nsis3-metro.bmp" # Set the picture to the left of the welcome and finish interface. # Display a checkbox the user has to check to agree with the license terms !define MUI_LICENSEPAGE_CHECKBOX # Use the check boxes to confirm the installation protocol. !define MUI_LICENSEPAGE_CHECKBOX_TEXT "$(STR_LicenseAccept)" # The text of the check box. # The bitmap with images for the checks of the component select treeview !define MUI_COMPONENTSPAGE_CHECKBITMAP "check.bmp" # Select the picture of the check box for installing the component interface, which can be customized. # Do not automatically jump to the finish page, to allow the user to check the install log !define MUI_FINISHPAGE_NOAUTOCLOSE # Do not skip the process interface automatically after installation. # Show a message box with a warning when the user wants to close the installer !define MUI_ABORTWARNING # A prompt pops up when you exit the installation halfway. # Text for a link on the which the user can click to view a website or file !define MUI_FINISHPAGE_LINK "$(STR_ViewMoreInfo)" # Show a link on the completion interface, this is the text on the link. # Website or file which the user can select to view using the link !define MUI_FINISHPAGE_LINK_LOCATION "http://tieba.baidu.com/p/6196474861" # The actual address of the link. # Show all languages, despite user's codepage !define MUI_LANGDLL_ALLLANGUAGES # Force display of all supported languages. #-------------------------------- # Installer pages # The interface to be displayed in the installation package should be noted that it is displayed in the order of insertion. # Include welcome page !define MUI_PAGE_CUSTOMFUNCTION_LEAVE "OnPageWelcomeLeave" # This function is called when you click the next button in the welcome screen. !insertmacro MUI_PAGE_WELCOME # The first thing to insert is the welcome screen. # Create a custom donate page Page custom "OnPageDonateCreate" # Insert a custom interface. # Include license page !insertmacro MUI_PAGE_LICENSE $(STR_License) # Insert the protocol confirmation interface. # Include directory selection page !define MUI_PAGE_CUSTOMFUNCTION_LEAVE "OnPageDirectoryLeave" # This function is called when you click the next button on the Select Installation Path interface. !insertmacro MUI_PAGE_DIRECTORY # Insert the Select Installation Path interface. # Include install files page !insertmacro MUI_PAGE_INSTFILES # Insert the installation process interface. # Include finish page !insertmacro MUI_PAGE_FINISH # Insert the completion interface. #-------------------------------- # Languages # Define the language to support. !insertmacro MUI_LANGUAGE "SimpChinese" # Simplified Chinese, will define LANG_SIMPCHINESE Variable. !insertmacro MUI_LANGUAGE "TradChinese" # Traditional Chinese, will be defined LANG_TRADCHINESE Variable. #-------------------------------- # Language strings # Defines a multilingual version of some strings. # Use parentheses when using multilingual strings, for example $() Instead of ${} LangString STR_ProductName ${LANG_SIMPCHINESE} "VNR Translation Repair Patch 1.4" LangString STR_ProductName ${LANG_TRADCHINESE} "VNR Translation Repair Patch 1.4" LangString STR_AppIsRunning ${LANG_SIMPCHINESE} "Detected VNR Running, please exit it and try again." LangString STR_AppIsRunning ${LANG_TRADCHINESE} "Detected VNR Running, please exit it and try again." LangString STR_DonatePageTitle ${LANG_SIMPCHINESE} "Support Author" LangString STR_DonatePageTitle ${LANG_TRADCHINESE} "Support Author" LangString STR_DonatePageSubTitle ${LANG_SIMPCHINESE} "cat~" LangString STR_DonatePageSubTitle ${LANG_TRADCHINESE} "cat~" LicenseLangString STR_License ${LANG_SIMPCHINESE} "license.zh-cn.rtf" LicenseLangString STR_License ${LANG_TRADCHINESE} "license.zh-tw.rtf" LangString STR_LicenseAccept ${LANG_SIMPCHINESE} "I have backed up these folders(&A)" LangString STR_LicenseAccept ${LANG_TRADCHINESE} "I have backed up these folders(&A)" LangString STR_WrongInstallDirectory ${LANG_SIMPCHINESE} "The folder you selected is not VNR Please re-select the installation folder of." LangString STR_WrongInstallDirectory ${LANG_TRADCHINESE} "The folder you selected is not VNR Please reselect the installation folder of." LangString STR_ViewMoreInfo ${LANG_SIMPCHINESE} "Browse the posts to see more information(&M)" LangString STR_ViewMoreInfo ${LANG_TRADCHINESE} "Browse the posts to see more information(&M)" #-------------------------------- # Version Information # Defining the output EXE Version information on the file also supports multilingual display. VIProductVersion "1.4.0.0" VIFileVersion "1.4.0.0" VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "ProductName" "VNR Translation Repair Patch" VIAddVersionKey /LANG=${LANG_TRADCHINESE} "ProductName" "VNR Translation Repair Patch" VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "ProductVersion" "1.4.0.0" VIAddVersionKey /LANG=${LANG_TRADCHINESE} "ProductVersion" "1.4.0.0" VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "LegalCopyright" "Shiroha" VIAddVersionKey /LANG=${LANG_TRADCHINESE} "LegalCopyright" "Shiroha" VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "FileDescription" "Application Installer" VIAddVersionKey /LANG=${LANG_TRADCHINESE} "FileDescription" "Application Installer" #-------------------------------- # Reserve Files # Keep special files that are compressed separately to quickly locate and uncompress data when the installation package starts. # If you are using solid compression, files that are required before # the actual installation should be stored first in the data block, # because this will make your installer start faster. !insertmacro MUI_RESERVEFILE_LANGDLL # Reserved for multilingual support plugins DLL File. # QR code image file ReserveFile "donate.bmp" # Keep a custom picture file. #-------------------------------- # Installer Sections # Define the components of the installation process. The installation package must have at least one component.If you have multiple components, you need to define multiple. # Components can define component names and perform installation priorities. # Commands written in components are executed sequentially during installation. Section # This installation package has only one component. # Sets output directory SetOutPath "$INSTDIR" # Set the file output path to the installation path. # Files File /r "Files\*.*" # Define the file to unpack. # This command is special in that it defines both the files to be packaged and the files to be unpacked at installation time. # The path defined here is the path to the file to be packaged, which is represented by a wildcard character Files All files in a directory can also be specified as a single file. # When installed, the file will be unpacked to SetOutPath The path set. # If File The command defines several files and unpacks them according to the directory structure, just like you normally unpack them. SectionEnd #-------------------------------- # Installer Functions # Define all functions to be used by the installation package. # according to NSIS As a scripting convention, functions must be written at the end of the script. Function ".onInit" # To "." The starting functions are built-in callback functions that are automatically executed at specific times. # This function is executed first when the package starts. # $PLUGINSDIR will automatically be removed when the installer closes InitPluginsDir # This command is used for initialization $PLUGINSDIR This variable, the general path is "User Temporary Directory"\ns Random Characters.tmp\" # Show the language selection dialog !insertmacro MUI_LANGDLL_DISPLAY # Show the language selection dialog. # Extract QR code image file File "/oname=$PLUGINSDIR\donate.bmp" "donate.bmp" # Unpack custom pictures into a temporary directory. FunctionEnd Function "OnPageWelcomeLeave" # This function is called when you click the next button in the welcome screen. ${nsProcess::FindProcess} "python.exe" $R0 # Find the name " python.exe" Process that saves results to $R0 In a register. ${If} $R0 != 0 # If not, try to find another one. ${nsProcess::FindProcess} "pythonw.exe" $R0 # Find a name pythonw.exe" Process that saves results to $R0 In a register. ${If} $R0 != 0 # If you don't find it, you can start the installation. ${nsProcess::Unload} # Manually uninstall this plugin when it is used up. Return # Call back indicates that you can enter the next installation interface. ${EndIf} ${EndIf} ${nsProcess::Unload} # Manually uninstall this plugin when it is used up. MessageBox MB_ICONEXCLAMATION|MB_OK "$(STR_AppIsRunning)" # Check that the program is running and a message box pops up. Abort # call Abort Indicates that you are not allowed to enter the next installation interface. FunctionEnd Function "OnPageDonateCreate" # This function is called when the interface defined above is created. !insertmacro MUI_HEADER_TEXT "$(STR_DonatePageTitle)" "$(STR_DonatePageSubTitle)" # Set the main and subtitle of the page nsDialogs::Create 1018 # To create an interface, the parameters are usually fixed to "1018", unless you intend to create a very special interface or dialog box. ${NSD_CreateBitmap} 0 0 100% 100% "" # Create a picture frame with 0 on the left,0"Size is "100"%,100%",The handle to the picture box is pushed onto the stack. Pop $R0 # Eject the handle of the picture box from the stack and save it $R0 Register. ${NSD_SetImage} $R0 "$PLUGINSDIR\donate.bmp" $R1 # Set a picture to the picture frame and return a picture handle to save $R1 Register, need to be released manually. nsDialogs::Show # Show the interface. ${NSD_FreeImage} $R1 # Release the picture handle. FunctionEnd Function "OnPageDirectoryLeave" # This function is called when you click the next button on the Select Installation Path interface. ${IfNot} ${FileExists} "$INSTDIR\Visual Novel Reader.exe" # Check that the user's chosen installation path exists. Visual Novel Reader.exe"This file. MessageBox MB_ICONEXCLAMATION|MB_OK "$(STR_WrongInstallDirectory)" # There is no path selection error, pop up a prompt box. Abort # call Abort Indicates that you are not allowed to enter the next installation interface. ${EndIf} FunctionEnd #-------------------------------- # End of script
The results are as follows:
(Language Selection Interface)
(Welcome interface)
(Custom interface)
(Protocol interface)
(Select the installation path interface)
(Installation process interface)
(Complete the interface)
The above script is a simple example and does not include features such as Install or Uninstall Programs registration that require writing to the registry, shortcuts, or uninstallers.This example simply unpacks the file to the specified directory.
If you have read this example and you still don't understand it, be sure to look at the Examples folder in the NSIS installation directory, which demonstrates the use of various functions and commands.I'll learn it soon.I spent a day, too.