This article is a mirror article of machine translation, please click here to jump to the original article.

View: 3956|Reply: 6

NSIS (1) Make a simple installer

[Copy link]
Posted on 1/28/2024 9:42:28 AM | | | |
Requirements: Developed an application using Winform, and wanted to make an installer to install and execute this application, showing that the product is more formal.

Introduction to NSIS

NSIS (Nullsoft Scriptable Install System) is a professional open-source system for creating Windows installers. It is designed to be as small and flexible as possible, making it ideal for internet distribution.

As a user's first experience with a product, a stable and reliable installer is an important part of successful software. With NSIS, you can create such an installer that is capable of performing all the operations required to install software.

NSIS is script-based, allowing you to create logic to handle the most complex installation tasks. Many plugins and scripts are already available: you can create web installers, communicate with Windows and other software components, install or update shared components, and more.


NSIS Download:

The hyperlink login is visible.
The hyperlink login is visible.

NSIS Plugins:The hyperlink login is visible.

HM NIS EDIT download:

The hyperlink login is visible.
The hyperlink login is visible.

HM NIS EDIT: Free NSIS Editor/IDE: HM NIS Edit is the best editor/IDE for Nullsoft Script Installation System (NSIS). It is very useful for experts and beginners who use NSIS to create installers. Its script wizard will help you create a standard installer with just a few clicks, and its InstallOptions designer will help you create your own custom pages with a friendly drag-and-drop interface.

Download and install

Download the NSIS and HM NIS EDIT software, install NSIS first, and then install HM NIS EDIT, as shown below:



Make an installation package

Create a new Winform application, use the IDE tool to create a new Winform application of .NET framework 4.7.2 (omitted), compile it, and use NSIS to create an installation package.

Open the HM NIS EDIT tool and select File-> New Script: Wizard, as shown below:



Customize the application information according to your actual situation, as shown in the figure below:



Uncheck "English" and select "Simplified Chinese" as shown in the following figure:



Set the authorization file path as shown in the following figure:



Specify the application file, delete the existing configuration, and then add our application directory as shown in the figure below:




Click Next, as shown below:



Please fill in the program, parameters, and self-report according to your own situation, as shown in the figure below:



Uninstall the program configuration as shown in the following figure:



The last step is to save it as a test.nsi script for the next compilation, as shown below:



Compile the script and generate the installation package as shown in the figure below:



Attach the test.nsi code:

(End)





Previous:Explore topics in the .Net Reactive Responsive Extension
Next:NSIS (ii) mutex guarantees that only one installer is running
 Landlord| Posted on 1/28/2024 10:09:14 AM |

functionsignificance
SectionThe most basic function represents a department, used to represent a component that needs to be installed, the content of the section is the last part of the program to be executed except for uninstalling, but it will be the first to check when compiling, if there is no section or function in the program, the compilation will be terminated, and the code block in the section needs to be indented to 2 spaces
FunctionThe executed function also needs to be indented, its function name will be recognized, if it is recognized as a special name, it will be carried out under specific circumstances, which will be explained below
SectionEndIndicates the end of the department, not indented inside the section
FunctionEndIndicates the end of the function, same as above
SetCompressorSet the compression algorithm, the following parameters are the compression algorithm in the wizard, solid use /SOLID as the prefix, e.g., solid lzma algorithm is written as /SOLID lzma
SetCompressorSet the compressed volume size, followed by a number, and it usually doesn't matter if you don't write it
OutFileDecide on the path of the compiled installation package (the path of future installation packages, not which folder to put it in)
NameSet the name of the product, usually the application name + app version written in the first step of the wizard
InstallDirRepresents the default installation path, which is filled in in the first line of the fourth step of the wizard, which determines the value of $INSTDIR
ShowInstDetailsThe parameters are not simple true and false, but show, hide and nevershow, which indicate that the details are automatically displayed, the user button displays the details, and the installation details are not allowed to be seen
ShowUnInstDetailsIndicates whether the uninstallation details are displayed, and the parameters are the same as above
BrandingTextDisplays the information at the bottom of the installation package, that is, the last line of custom text in the first step of the wizard, which can accept two parameters, one is the text to be displayed, and the optional parameter is /TRIM, which can determine the direction of text alignment (LEFT, RIGHT or CENTER, the default is LEFT, /TRIMLEFT, /TRIMRIGHT or /TRIMCENTER must be written, without any separation in between)
SetOutPathIt can only be written on the first line of the Section, which determines the installation location of the component represented by the Section, different from InstallDir, SetOutPath allows different components to be installed in different subdirectories of the total installation directory, it is recommended to set it to $INSTDIR\ folder with the component name (or if the components are interdependent, you can adjust the component path separately)
SetOverWriteIt can only be written in Section, which is used to set whether to overwrite when installed, and the parameters can be set to always overwrite (on), never overwrite (off), overwrite when newer (ifnewer), overwrite when the file content is different (ifdiff) and try to overwrite (try), corresponding to the fifth step of the wizard > editing directory items
FileIt can only be written in Section, which means that the Section contains and packaged files, and the /r escaping parameter represents files and folders containing subdirectories, and the corresponding wizard steps are the same as above. /x parameter is used to exclude files, you can write /x "*.ico" "xxx\*", which means to exclude ICO files and exclude all files in the xxx subdirectory, corresponding to step 5 of the wizard
CreateDictionaryCreate a folder followed by the full or relative path of the folder
CreateShortcutCreate a shortcut, the first is the path of the shortcut (suffix .lnk), and the second is the path of the shortcut to the file, corresponding to the lower part of step 6 of the wizard
WriteUninstallerCreate an uninstaller followed by the path name of the uninstaller
WriteRegStrWrite to the registry, which generally does not need to be changed, just follow the wizard to generate
DeleteUsually in the uninstall section, delete a single file, followed by the path of the deleted file, because it is a single file, you cannot add /r
RMDirUsually in the uninstall section, delete the directory and all files in the directory, followed by the path of the deleted directory, the first generally needs to manually add /r, the wizard did not add it to you, if you don't add it, it will uninstall the residue, it is best to write this command once for each subdirectory, you have to add /r, and finally remove the general directory RMDir "$INSTDIR"
DeleteRegKeyTo delete the registry information, you can generally follow the wizard to generate it
SetAutoCloseIt can only be written in the Section, indicating whether it will automatically jump to the completion interface after the installation is completed, with the parameters of true and false
AutoCloseWindowIt doesn't seem to have any effect, the function seems to be the same as the previous one, but it can be written outside the section, and the parameters are the same as above
MessageboxThe message box can only be written in Section or Function, there are many parameters, including display information, display warning, ask yes no, ask okcancelretry, etc., enter Messagebox in VNISEdit to get a list of all parameters, and then connect the content displayed in the message box
Abortblocking, waiting for the user to answer
HideWindowHidden window, usually used to uninstall Section, the uninstaller deletes itself first, then deletes other files (yes, the program is still running), and automatically closes the window after deletion


 Landlord| Posted on 1/28/2024 11:07:28 AM |
callback function

Callback function at installation

.onGUIInit
.onInit
.onGUIEnd
.onRebootFailed
.onSelChange
.onUserAbort
.onVerifyInstDir

Callback function on uninstall

un.onGUIInit
un.onInit
un.onUninstFailed
un.onUninstSuccess
un.onGUIEnd
un.onRebootFailed
un.onSelChange
un.onUserAbort


The details are as follows:

onGUIInit:
The callback will be called before the first page loads and the installer dialog is displayed, allowing you to adjust the user interface.

onInit:
This callback will be called when the installer is close to completing initialization. If the .onInit function calls Abort, the installer exits immediately.

onInstFailed:
This callback function is called when the user clicks the "cancel" button after an installation failure (if the installer cannot release any files, or if the installation script uses the Abort command).

onInstSuccess:
The callback is called before the installation is successful and the installation window closes (if AutoCloseWindow or SetAutoClose is set to false, it may be after the user clicks "Close").

onGUIEnd:
The callback is called just after the installer window is closed. Use to release any plugins related to the user interface when needed.

onMouseOverSection:
The callback is invoked whenever the mouse moves over the tree section selection box. This allows you to set a sample description for each segment. The ID of the current segment where the mouse hover is located has been temporarily saved at $0.

onRebootFailed:
This callback function is called when the Reboot instruction fails. WriteUninstaller, plug-ins, File, and WriteRegBin cannot be used for this callback function.

onSelChange:
Called when the component selection page options are changed. Commonly used to use SectionSetFlags and SectionGetFlags.

onUserAbort:
This callback is called when the user clicks the "cancel" button and the installation has not yet failed. If the function calls Abort, the installation will not exit.

onVerifyInstDir:
This callback allows your installer to control whether the installation path is valid or not. This code is called once every time the user changes the installation path. If the function calls Abort, the path to $INSTDIR is considered invalid.

un. GUIInit:
The callback will be called before the first page loads and the Uninstaller dialog is displayed, allowing you to adjust the uninstaller interface.

un.onInit:
This callback will be called when the uninstaller is close to completing initialization. If the un.onInit function uses Abort, the uninstaller exits immediately. Note: The function can validate and/or modify the $INSTDIR if needed.

un.onUninstFailed:
This callback function is called when the user clicks the "Cancel" button after an uninstall fails (if the Abort command or other failed command is used).

un.onUninstSuccess:
The callback is called before the uninstall is successful and justifiably closes the uninstaller window (possibly after the user clicks "close" if SetAutoClose is set to false).

un.onGUIEnd:
The callback is called just after the uninstaller window is closed. Use to release any plugins related to the user interface when needed.

un.onRebootFailed:
This callback function is called when the Reboot instruction fails. WriteUninstaller, plug-ins, File, and WriteRegBin cannot be used for this callback function.

un.onUserAbort:
This callback is called when the user clicks the "Cancel" button and the uninstall has not failed. If the function calls Abort, the uninstaller will not exit.

 Landlord| Posted on 1/28/2024 12:07:23 PM |
Call must be used with function names starting with "un." in the uninstall section.
Usage: Call function_name | [:label_name]


NSIS has naming conditions - functions called from the uninstaller must have a prefix in the "un" name.

The solution is as follows:

Reference:

The hyperlink login is visible.
The hyperlink login is visible.

 Landlord| Posted on 1/28/2024 3:10:07 PM |
 Landlord| Posted on 5/9/2024 9:46:16 AM |
Advanced Installer is a powerful MSI installation package maker that generates MS Windows Certified Windows Installers with a user-friendly graphical user interface, intuitive and very simple interface, making it a good Windows Installer writer.
 Landlord| Posted on 2/21/2025 5:36:44 PM |
Inno Setup is a free Windows program installer developed by Jordan Russell and Martijn Laan. Inno Setup was first launched in 1997 and today rivals and even surpasses many commercial installers in terms of feature set and stability.

Website:The hyperlink login is visible.

Case: Ollama Windows application,The hyperlink login is visible.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com