NSIS script details

Source: Internet
Author: User

From: http://9goo.blogchina.com/9goo/6414594.html

Some scripts require additional DLL support, such as the program associated with the PC, it may need installoptionsex. dll,
In addition, you may need to compile the Language header file such as simpchinese. nsh! Replace all define! Insertmacro mui_default, and so on in other languages! There are also some people who need to explore in the production process! I will not mention them here.

Script structure:

Installer properties-page-section-uninstall the installer (this is only a general structure and can contain "variable" "function ".....)

Installer attributes:
;--------------------------------------
Name "your program name is defined here"

Setcompressor "[/solid] [/FINAL] zlib | Bzip2 | lzma"
* This command is used by the installer to determine whether the data should be compressed *

Crccheck "on | off | force"
* Whether the installer executes a CRC for itself before installation *

InstallColors "/windows | (foreground color background )"
* Set the installation information screen color (default: 00FF00 000000 )*

AutoCloseWindow "true | false"
* Set whether the window is automatically closed when the installation is complete *

ShowInstDetails "hide | show | nevershow"
* Set whether to display Installation Details *

SilentInstall "normal | silent | silentlog"
* Specifies whether the installer is installed silently *

BrandingText "/TRIM (LEFT | RIGHT | CENTER) text"
* Set the text displayed at the bottom of the installer window *

SpaceTexts "{space text required [available space text]}"
* If a parameter is specified, the required space and available space text for installation will be replaced *

Caption "title"
* When an external PageEx block is used: Set the installer title text *

SubCaption "[Page code subtitle]"
* Replace each installer page (0 = ": License Agreement", 1 = ": Installation Options", 2 = ": installation directory", 3 = ": Installing ", 4 = ": Installation Complete. If an empty string ("") is specified, the default value is used (you can also specify "" to use a blank string )*

InstallButtonText "installation button text"

ComponentText "[Text [subtext] [subtext 2]"
*/Used to change the default text on the component selection page

Text: the text on the control, to the right of the installation icon

Sub-text: select the control text for the installation type

Sub-text 2: select the text below the control and on the left of the component list for the installation type

If the string is null (""), use the default text /*

 

OutFile "[path \ drivers installer .exe"

! Include "file" (for example :! Include "MUI. nsh") MUI is a custom UI header file.
* This command can include a file in the script, just like a part of the script *

;--------------------------------------

Page:

If you use "! Include "MUI. nsh" is defined as follows;
! Define MUI_ICON ". \ The icon you want to use"
! Define MUI_HEADERIMAGE
! Define MUI_HEADERIMAGE_RIGHT
! Define MUI_HEADERIMAGE_BITMAP. \ select an image with the number of 150*57 images (the image must be in BMP Format)
For details, open MUI. nsh;
;-----------------------------------------------------
If not
Page license Agreement Page
Page components component selection Page
Page directory installation directory selection Page
Page instfiles installation execution Page
Uninstpage uninstconfirm uninstallation confirmation page
Uninstpage instfiles uninstallation

Installdir defines the installation directory
Installdirregkey HKLM software \??? ""
;-----------------------------------------
Section:
Before the description, I will first describe "insttype", insttype definition:
Add an installation type to the installation type list, or disable custom installation types;
Example:
Insttype "Recommended installation"
Insttype "Install all"
By default, "custom installation" is available. Of course, you can disable it!

Take a look at the Section;
Section
...............
Sectionend
The above section is just an empty area!
Let's look at an example:
;-----------------------
Insttype "Recommended installation"
Insttype "Install all"

Section "section 1"
Sectionin 2
Sectionend

Section "section 2"
SectionIn 1 2
SectionEnd
;----------------------
I don't know if you can see it. In this example, we want to tell you that when we select "Recommended installation", we only install the content in section 2, when we select "Install all", we have installed "section 1" and "section 2.

If we need an installation option in a segment, we need to use the "segment group"
SectionGroup [/e] partition group name [partition group name index output] * If/e is specified, all segments of the partition group will be expanded by default *
Example:
;--------------------------------
SectionGroup "area group"
Section "Section 1"
SectionEnd
Section "Section 2"
SectionEnd
SectionGroupEnd
;--------------------------------

The following describes how to uninstall the installer:
;-------------------------------
; Uninstaller
Section "Uninstall"
SectionEnd
;-------------------------------
The above is the unloading section!

After reading the introduction above, we can write a little bit about it. Although nothing is executed, the framework is ready, isn't it?

**************************************** ********************************
Common commands and functions (most of which are used in segments)

1: file [/nonfatal] [/a] ([/r] [/x file | wildcard [...] (File | wildcard) [...] |/oname = output path \ file name input path \ file name)
Release the file to the current output path.
If the/nonfatal switch is used and the file is not found, use a warning instead of an error.
If the/a switch is used, the attributes of the added file are maintained.
If the/r switch is used, the matched file will be searched recursively In the subdirectory. If the directory name matches, all contained content will be recursively added. The directory structure is also maintained.
The/x switch can be used to exclude files or directories.

Commands for detaching segments:
Delete [/REBOOTOK] File
Delete a file from the target system

2: WriteRegStr root key sub-key value

Write the string to the Registry.

WriteRegExpandStr root key sub-key value

Write the string to the Registry. The root key must be one of the following lists:
Hkcr or hkey_classes_root
HKLM or HKEY_LOCAL_MACHINE
Hkcu or HKEY_CURRENT_USER
HKU or HKEY_USERS
HKCC or hkey_current_config
Hkdd or hkey_dyn_data
Hkpd or hkey_performance_data
Shctx or shell_context
If the string cannot be written to the Registry, place an incorrect flag. The string type is REG_SZ corresponding to writeregstr, or reg_expand_str corresponding to writeregexpandstr. If the registry key does not exist, it is automatically created.

Commands for detaching segments:
Deleteregkey [/ifempty] root key sub-Key
Delete a registry key. If/ifempty is specified, the registry key is deleted only when it has no sub-Key (otherwise, the entire registry key is deleted ). Valid root key values are listed in the following writeregstr. If the key cannot be deleted (or if it does not exist), an error mark is placed.

3: setoutpath output path

Set the output path ($ outdir) and create it when the path does not exist (recursively create it if necessary ). It must be a full path name. $ instdir is usually used.

To put it bluntly, it is like the "Create a directory" command in DOS.

For example:
Setoutpath $ instdir
?? What directory is this? The variable "installation directory" corresponds to the previous definition.
"Installdir $ ProgramFiles \ quhail", this is our directory!
Corresponding uninstall command:
Rmdir directory to be deleted

4: createdirectory path to be created
Creates (recursively creates) the specified directory. When a directory cannot be created, an error mark is placed.

You can also specify an absolute path.
Createshortcut
Shortcut file. lnk target file [parameter [icon file [icon index number [startup option [keyboard shortcut key [description]

Create a shortcut "shortcut file. lnk" pointing to the "target file", which can contain the "parameter.
Is to create a shortcut

Corresponding uninstall command:
Delete

5: regdll file [Entry Point name]
Load the specified DLL and call the dllregisterserver (or entry point name, after which ). When an error is generated, an error mark is set (for example, the DLL cannot be loaded, the OLE cannot be initialized, the entry point cannot be found, or the function returns any other error error_success (= 0 )).

It is actually registering or loading the plug-in you want!
Example: RegDLL $ INSTDIR \ Codecs \ hsf-dec. ax
Corresponding uninstall command
UnRegDLL

6: Exec command
This should be a common command. to execute a specified program and install it immediately, you can directly execute a program.
ExecWait Command [user variable (return code)]
Execute a specified program and wait until the processing ends.
For example, run an installation file. inf.
ExecWait "RunDll32 advpack. dll, LaunchINFSection skins. inf, defainstall install"
Corresponding uninstall
ExecWait "RunDll32 advpack. dll, LaunchINFSection $ windir \ INF \ skins. inf, DefaultunInstall"
Of course, DefaultunInstall is not fixed. For details, refer to the INF file. It can define [unInstall] OR [DEL] OR something else. It cannot be uninstalled without uninstalling a segment!

The above should be a simple installation package!

7: ReadINIStr user variable (output) INI file segment Item

Read the value of the item from the "segment" section of the "INI file" and output the value to the user variable. If this item is not found, an error mark is placed and the user variable is assigned a null value.

Corresponding uninstall
DeleteINISec INI file section
Delete the entire section "section" from the "INI file"
Deleteinisec $ Temp \ something. ini Field 2
Deleteinistr INI file segment string
Delete the "string" from the "segment" section in the "INI File.
Deleteinistr $ Temp \ something. ini Field 2 a component Installation

For example: Something. ini
[Field 1]
Type = label
TEXT = a component Installation
Left = 8
Right = 68
Top = 6
Bottom = 13

[Field 2]
Type = label
TEXT = B component Installation
Left = 5
Right = 65
Top = 44
Bottom = 51

8: reservefile [/nonfatal] [/R] [/X file | wildcard [...] File [file...]
Save the file in the data block that will be used later.

Used for the following calls.
Sometimes, pre-package files to facilitate installation and acceleration of release.
For example, ReserveFile "a. ini"

9: Function [Function name]
Start and open a new function.
Function func
............
FunctionEnd
;----------------
Define the function "func" in this section"

9: StrCpy user variable (target) string [maximum length] [Starting OFFSET]
String Copy command
For example
StrCpy $0 "a bbbbbbbbbb" $0 = "a bbbbbbbbbb"
StrCpy $0 "a bbbbbbbbbb" 3 $0 = "a B"
............

10: Mark of simultaneous jump of StrCmp string 1 string 2 [mark of simultaneous jump]
Comparison (Case Insensitive): "string 1" and "string 2". If the two are the same, jump to "simultaneously redirected tag". Otherwise, jump to "not simultaneously redirected tag ".

11: Exch [user variable | stack Index]
If no parameter is specified, two units at the top of the stack are switched.
Push string
Press a string into the stack. This string can then pop up from the stack
Pop user variable (output)
A string pops up from the stack to the user variable $ x. If the stack is empty, an error mark is set.
For example:
Push 1
Push 2
Exch
Pop $0 # = 1

12: if
12-1 mark to jump when IfAbort exits [not the mark to jump when exiting]
If the call exits, it returns true.
12-2 marker for redirect when an IfErrors error occurs [no marker for redirect when an error occurs]
Check and clear the error mark. If an error mark is set, the system jumps to the "Jump mark when an error occurs". Otherwise, the system jumps to the "Jump mark when no error occurs ".
12-3IfFileExists: the marker to jump when the object to be detected exists [the marker to jump when the object does not exist]
Checks whether the "file to be checked" exists (wildcards or directories can be used), and jumps to "jump when the file exists" when the file exists; otherwise, jumps to "jump when the file does not exist ".

13 Goto: tag to jump | + offset |-offset | user variable (target address)
If a tag is specified, the system jumps to the "tag to jump :".

14 MessageBox message box Option List Message box text [/SD return] [detection return value jump to tag] [detection return value 2 jump to tag 2]
Displays a message box containing "message box text. The "message box option list" must be one or more of the following items. Separate multiple items using |.
Mb_ OK-show OK button
Mb_okcancel-the OK and cancel buttons are displayed.
Mb_abortretryignore-the exit, retry, and ignore buttons are displayed.
Mb_retrycancel-display retry and cancel buttons
Mb_yesno-display the buttons "yes" and "no"
Mb_yesnocancel-display "yes", "no", and "cancel"
Mb_iconexclamation-display the exclamation point icon
Mb_iconinformation-display information icon
Mb_iconquestion-display question mark icon
Mb_iconstop-display the termination icon
Mb_topmost-Display message boxes at the frontend
Mb_setforeground-set the foreground
Mb_right-right-aligned text
Mb_rtlreading-RTL reading sequence
Mb_defbutton1-button 1 by default
MB_DEFBUTTON2-button 2 by default
MB_DEFBUTTON3-button 3 by default
MB_DEFBUTTON4-button 4 by default
The "Check return value" can be 0 (null or left closed), or one of the following:

IDABORT-exit button
IDCANCEL-Cancel button
IDIGNORE-ignore button
IDNO-No
IDOK-OK button
IDRETRY-Retry button
IDYES-Yes button
If the return value of the message box is "Detection return value", the installer will perform a jump.
For example:
IfFileExists "$ EXEDIR \ mplayerc.exe" + 3 0
MessageBox MB_ OK | MB_ICONEXCLAMATION "Put it in the MY nmlookou directory to run"

15: Rename [/REBOOTOK] target file of the source file
Rename the source file to the target file
For example:
Rename $ INSTDIR \ file. ext $ INSTDIR \ file. dat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.