NSIs installation Package (vii) _ Sample script syntax parsing

Source: Internet
Author: User
Tags date now

NSIs Installation Package _ Sample script syntax parsing

The previous section describes the NSIs installation Package _ Wizard script Primary personalization, although the end of "more personalized, please look forward to", but in the next few are not going to continue to explain how to personalize the script, but to return to the basic syntax and the NSIs of further understanding.

The last section is only very blunt in the explanation of a few personalized, if it is helpful to others, but only to give people to fish, according to a few personalized changes, it is impossible to think of any place can be personalized and how personalized. To teach people to fish, they must learn and share more common knowledge and skills .

First of all, grammar is essential, but even in Chinese, few people are willing to read the Help document (though this should be a piece of cake for programmers). This section focuses on the syntax that is involved in the wizard script in the previous section, which opens the door to mastering grammar. When the grammar and related knowledge to a certain extent, then go to the system to read the Help file, check leakage fill, it will be much easier, and the system master NSIs very helpful.

If necessary, download the sample script:

http://download.csdn.net/detail/signjing/4540492

Here is the code and parsing, where the background part is the script content. annotations,!define, variables,!include, constants

; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard Helper defines

!define product_name "signjing installation Sample"

!define product_version "0.0.0.1"

!define product_publisher "Signjing"

!define product_web_site "Http://blog.csdn.net/signjing"

!define product_dir_regkey "Software\microsoft\windows\currentversion\app Paths\genpat.exe"

!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

......

; personalized graphic element;

!define mui_welcomefinishpage_bitmap "C:\util\nsis_uis\ White Jade Mountain tower. bmp"

!define mui_welcomepage_title "\ r \ n signjing installation Sample Wizard"

!define Mui_welcomepage_text "Signjing Installation example is a NSIs installation sample software developed by Signjing. \r\n\r\n Software Author: signjing \r\n\r\n Official website: http://blog.csdn.net/signjing\r\n\r\n $_click "

Notes

To or #开始的行为注释行. You can add a comment after the command, or you can annotate one or more lines with a comment from the C specification. If the argument needs to start with A; or #, you can enclose it in double quotes.

Such as:

; Comments

# comments

/*

Comments

Comments

* * !define

[/date] symbol [value]

This command will add "symbols" to the global definition list. This effect is similar to using the/d command-line switch effect on the compiler. (the definition is valid only after the!define command)

If/date is used, the defined values are formatted as strtime. Strtime converts the current time date to the actual value. For example,%H will be converted to the 24-hour format for the current time. Full formatted list of strings you can find MSDN. On the POSIX platform, you can use man strtime to get the list.

Such as:

!define use_something

!define VERSION 1.2

!define/date Now "%h:%m:%s%d%b,%Y" variable

All variables are global and can be used for extents and functions. It should be noted that the variable is limited to 1024 bytes by default. To enlarge this limit you will need to reconstruct a nsis using a larger Nsis_max_strlen value or use a special version. !include

File This command can include a file in a script, just as part of a script. Note that if a file is contained in another directory, the current directory is still where the script was compiled (not the directory where the file is being included). If the compiler cannot find the file, it will be looked up in each containing directory. Constants

Constants are often used in installdir properties.

It should be noted that some of the new constants are not normal on all OS. For example $CDBURN _area is only normal in Windows XP and above systems. If used in Windows 98, you will get a null value. Unless specifically prompted, the constant is valid on all OS.

$PROGRAMFILES

program file directory (usually C:\Program files but runtime detects).

$COMMONFILES

Common file directory. This is the directory where the application shares components (typically C:\Program Files\Common Files but runtime detects).

$DESKTOP

The Windows Desktop directory (usually C:\windows\desktop but runtime detects). The content of the constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default.

$EXEDIR

The location of the installer at run time. (Technically you can modify the variable, but it's not a good way).

${nsisdir}

Contains a tag for the NSIs installation directory. is detected at compile time. Often used when you want to call a resource in the NSIs directory, such as: Icon, interface ...

$WINDIR

Windows directory (usually C:\windows or C:\winnt but will be detected at run time)

$SYSDIR

Windows system directory (usually C:\windows\system or C:\winnt\system32 but will be detected at run time)

$TEMP

System temp directory (usually C:\windows\temp but will be detected at run time)

$STARTMENU

Start Menu directory (often used to add a Start menu item, use CreateShortcut). The content of the constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default.

$SMPROGRAMS

Start Menu Program directory (you can use it when you want to locate $STARTMENU \ Program). The content of the constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default.

$SMSTARTUP

Start Menu program/Startup directory. The content of the constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default.

$QUICKLAUNCH

In IE4 Active Desktop and above the Quick Start directory. If the quick Start is not available, just return to the same as $TEMP.

$DOCUMENTS

The document directory. A typical path for a current user such as C:\Documents and Settings\foo\my Documents. The content of this constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default. This constant is not valid when Windows 95 and Internet Explorer 4 are not installed.

$SENDTO

This directory contains the send To menu shortcuts.

$RECENT

This directory contains shortcuts to the most recent documents of the user.

$FAVORITES

This directory contains shortcuts to users ' network favorites, documents, and more. The content of this constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default. This constant is not valid when Windows 95 and Internet Explorer 4 are not installed.

$MUSIC

The user's music file directory. The content of this constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default. This constant is only valid for Windows XP, me, and above.

$PICTURES

The user's picture directory. The content of this constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default. This constant is only valid for Windows 2000, XP, me, and above.

$VIDEOS

The user's video file directory. The content of this constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default. This constant is only valid for Windows XP, me, and above.

$NETHOOD

This directory contains linked objects that may exist in my network location, my web-places folder. This constant is not valid when Windows 95 and Internet Explorer 4 and the Active Desktop are not installed.

$FONTS

System font directory.

$TEMPLATES

Document Template directory. The content of this constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default.

$APPDATA

The Application Data directory. The current user path detection requires Internet Explorer 4 and above. The detection of all user paths requires Internet Explorer 5 and above. The content of this constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default. This constant is not valid when Windows 95 and Internet Explorer 4 and the Active Desktop are not installed.

$LOCALAPPDATA

The native Application Data directory. This constant is valid only for Windows 2000 or above systems ...

$PRINTHOOD

This directory contains linked objects that may exist in the Printers folder. This constant is not valid on Windows 95 and Windows 98.

$INTERNET _cache

The temporary files directory of Internet Explorer. This constant is not valid when Windows 95 and Windows NT and Internet Explorer 4 and Active Desktop are not installed.

$COOKIES

Cookies directory for Internet Explorer. This constant is not valid when Windows 95 and Windows NT and Internet Explorer 4 and Active Desktop are not installed.

$HISTORY

The history directory of Internet Explorer. This constant is not valid when Windows 95 and Windows NT and Internet Explorer 4 and Active Desktop are not installed.

$PROFILE

The user's personal configuration directory. A typical path, such as C:\Documents and Settings\foo. The constant is valid in Windows 2000 and above.

$ADMINTOOLS

A directory where administrative tools are saved. The content of this constant (all users or current users) depends on the Setshellvarcontext setting. The current user is assumed by default. This constant is valid for Windows 2000, me, and above.

$RESOURCES

The resource directory holds themes and other Windows resources (typically C:\Windows\Resources but detected at run time). This constant is valid for Windows XP and above.

$RESOURCES _localized

The local resource directory holds themes and other Windows resources (typically C:\Windows\Resources\1033 but detected at run time). This constant is valid for Windows XP and above.

$CDBURN _area

A directory where files are stored when the CD is burned. This constant is valid for Windows XP and above.

$HWNDPARENT

The decimal window handle of the parent window.

$PLUGINSDIR

The path is a temporary directory that is created the first time a plug-in is used or a call to Initpluginsdir. The folder is automatically deleted when the installer exits. The purpose of this folder is to save the INI file used by installoptions, the splash bitmap, or the files needed for other plug-ins to run.

constants used in strings

$$

Escape, used to represent $.

$\r

Used to represent a carriage return (\ r).

$\n

Used to represent a new row (\ n).

$\t

Used to represent a Tab (\ t). !insertmacro, Name, outfile, InstallDir, Installdirregkey, Showinstdetails , Showuninstdetails, Brandingtext

; Welcome page

!insertmacro Mui_page_welcome

; License page

!insertmacro mui_page_license "protocol license. RTF"

; Directory page

!insertmacro mui_page_directory

; Instfiles page

!insertmacro Mui_page_instfiles

; Finish page

!define mui_finishpage_run "$INSTDIR \bin\genpat.exe"

!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"

; outfile "${product_name}.exe"

outfile "Custom. exe"

InstallDir "$PROGRAMFILES \signjing Installation Sample"

Installdirregkey HKLM "${product_dir_regkey}" ""

Showinstdetails Show

Showuninstdetails Show

Brandingtext "signjing blog http://blog.csdn.net/signjing" !insertmacro

Macro name [parameters] [...]

Inserts the contents of a macro created by!macro. If you create a macro with parameters, you must transfer enough parameters to it as required by the macro.

!macro Print Text

Detailprint "${text}"

!macroend

!insertmacro Print "some text"

!insertmacro Print "Some more text" name

Name [double with name]

Sets the name of the installer. The name is usually used to display the name of the product, such as "my Program". If there is one or more ampersand (&) in the name, the second parameter is set to the same as the first, with A & where two & is used to denote it. For example, your product name is "Foo & bar2000", then use:

Name "Foo & bar2000" "Foo && bar2000"

If you have a & symbol in your installer name and use a langstring for the name, you will also need to create another name with a double & character as the second argument.

Accept variables. If you use a variable, the variable you use must be initialized in. OnInit. outfile

[Path \] Installer. exe

Specifies the output file makensis to write to the installer. Simply makensis the file to be written, it does not have any effect on the contents of the installer. installdir

The default installation directory sets the default installation directory. View the variables section to get the variables that are available for the string (especially $PROGRAMFILES). Note that the last \ later part of the string is preserved, and when the user chooses "browse" and gets a new catalog string at installation time, the section is automatically appended to the back (to prevent the behavior you need to add an extra \ After the catalog string, but you want to enclose the directory string with quotes to avoid being considered a line break). If it doesn't work, use the browse button. Installdirregkey

Root-Key subkey This property lets the installer detect a string in a registry, if the string is available then use it as the installation directory. If this property is preset, it crosses the installdir specified string when the specified registry key is available, otherwise using the default

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.