NSIS User Manual

Source: http://wenku.baidu.com/link?url=aWSWSEkhkdEBMi6OolvkZ7UYM0oi7B-9I50ufUiOwhGKkEC1NmbFE57BWoDAL5CmDNP0XvNV-Rr5OfERAqo-4zs76nPrHBb31Z3761-4k5e

 

NSIS (Nullsoft Scriptable Install System) is a tool for programmers to create Windows installers. It is released under an open source license and is completely free to use.

 

script file

    To make an installation package with NSIS, you must write an NSIS script, which is the text of some simple grammar rules.

    Each line of an NSIS script is a command. If the command is very long, you can use '/' to write a newline, similar to writing a long string in VC.

E.g:

Messagebox MB_OK|MB_ICONINFORMATION /

"This is a sample that shows how to use line breaks for larger commands in NSIS scripts"

If you want to add double quotes in the string, you can write: $/", or use single quotes instead.

 

    The extension of the script file is nsi, and the script header file is nsh. Script files can be organized into multiple header files, including header files in the following way:

!include Sections.nsh

 

script structure

    Script files generally include "Install Attributes", "Pages", "Sections", and "Functions".

    Install Attributes, which defines some constants, such as installation file name, installation path, etc.

    Pages, define the power of attorney page, the directory selection page, the component selection page, the uninstall page, and so on.

    Sections, the installation process is divided into multiple stages to define, easy to operate.

    Functions, define some functions for user interaction during installation.

script format

 

Commands

 The command line is of the form 'command [parameters]'

 File "myfile"

 

Comments

 Lines starting with ; or # are considered comment lines, you can put comments after the command line, or you can use c-style comments.

 ; Comment

 # Comment

 /*

  Comment

  Comment

 */

 File "myfile" ; Comment

If you need ; or # as arguments, you should put them in quotes.

 

Plug-ins

 The method called by the plugin: 'plugin::command[parameters]'

 nsExec::Exec "myfile"

 

Numbers

 As the value of the parameter, you can use integer, hexadecimal (starting with 0x), octal (starting with 0)

 Color values ​​are represented in hexadecimal, but do not start with 0x.

 IntCmp 1 0x1

 SetCtrlColors $HWND CCCCCC

 

Strings

 To represent a string with spaces, quotes should be used

 MessageBox MB_OK "Hi there!"

 Quotes only have the property of containing a parameter if they begin the parameter. Quotes can be single, double, or trailing single quotes (below the tilde).

 You can use $/ to indicate that the quote is part of a parameter

 MessageBox MB_OK "I'll be happy"

 MessageBox MB_OK 'And he said to me "Hi there"'

 MessageBox MB_OK `And he said to me "I'll be fucked"`

 MessageBox MB_OK "$/"A quote from a wise man$/" said the wise man"

 在字符串中,$/r,$/n,$/t分别表示回车,换行,制表。

 

Variables

 变量必须以$开头,变量必须先声明才可以使用,且大小写敏感。

 Var MYVAR

 StrCpy $MYVAR "myvalue"

 

Long commands

 若命令行较长需要多行写,你应该使用反斜杠进行换行(类似c++)。

 CreateShortCut "$SMPROGRAMES/NSIS/ZIP2EXE project workspace.lnk" /

  $INSTDIR/source/zip2exe/zip2exe.dsw"

 MessageBox MB_YESNO|MB_ICONQUESTION /

  "Do you want to remove all files in the folder? /

  (If you have anything you created that you want /

  to keep, click No)" /

  IDNO NoRemoveLabel

 

Configuration file

 若"makensis.exe"的目录下有"nsisconf.nsh"这样的文件,则该文件会被默认包含在任何脚本文件中,除非/NOCONFIG编译开关被指定。

变量

        所有的变量都是全局的,可在任何段落和函数中使用。

用户变量

        变量声明用Var命令,变量名可以用大小写字母和数字组合,且大小写敏感。

内置可读写变量

        $0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $R0, $R1, $R2, $R3, $R4, $R5, $R6, $R7, $R8, $R9

        这些变量可以当作用户变量使用,但通常用于公用函数和宏定义,你不用声明它们,同样在使用时也不会产生名字冲突。简易你在使用它们时,用栈保存和恢复它们的初始值,这些变量在插件中也是有效的,所以可用于插件交换数据。

        $INSTDIR

        安装目录(可用StrCpy,ReadRegStr,ReadINIStr等函数修改其值,例如,可在.onInit函数中验证安装目录)。

        需注意的是,在卸载代码中,$INSTDIR是卸载程序的目录,而不是在安装程序中指定的$INSTDIR的目录。例如,把卸载程序放在$WINDIR且用户无法移动它到其他位置,在卸载程序中,$INSTDIR和$WINDIR的值相同。若你把卸载放到其他位置,你应该在注册表中(或其他方式)保存安装程序的$INSTDIR,一边在卸载时读取。

        $OUTDIR

        当前输出目录(用SetOutPath设定,用StrCpy,ReadRegStr,ReadINIStr读取)。

        $CMDLINE

        安装程序的命令行。格式如下:

        ※ "full/path to/installer.exe" PARAMETER PARAMETER PARAMETER

        ※ installer.exe PARAMETER PARAMETER PARAMETER

        ※ 要解析PARAMETER,请用附录部分的GetParameters。如果/D=命令开关在命令中指定,它也不会在$CMDLINE中出现。

        $LANGUAGE

        当前使用的语言标识。例如英语是1033,你可在.onInit中改变该变量的值。

常量

        常量也可在InstallDir属性中使用。

        需注意的是,一些新添加的常量不是每个操作系统都拥有,如$CDBURN_AREA只有Windows XP及以上系统才有,而Windows 98没有。

        $PROGRAMFILES

        程序文件默认目录

        $COMMONFILES

        公共文件目录

        $DESKTOP

        Windows桌面目录

        $EXEDIR

        安装文件目录

        ${NSISDIR}

        NSIS安装目录。用于调用NSIS自带的图标、界面元素等资源。

        $WINDIR

        Windows目录。

        $SYSDIR

        Windows system目录

        $TEMP

        系统临时文件目录

        $STARTMENU

        开始菜单位置。

        $SMPROGRAMS

        开始菜单程序目录。

        $SMSTARTUP

        开始菜单启动目录

        $QUICKLAUNCH

        快速启动目录

        $DOCUMENTS

        文档目录。

        $SENDTO

        发送到目录

        $RECENT

        最近的文档目录。

        $FAVORITES

        $MUSIC

        $PICTURES

        $VIDEOS

        $NETHOOD

        $FONTS

        $TEMPLATES

        $APPDATA

        $LOCALAPPDATA

        $PRINTHOOD

        $INTERNET_CACHE

        $COOKIES

        $HISTORY

        $PROFILE

        $ADMINTOOLS

        $RESOURCES

        $RESOURCES_LOCALIZED

        $CDBURN_AREA

        $ HWNDPARENT

        parent window handle

        $PLUGINSDIR

Use constants in strings

        $$ is used in place of $

        $/r means carriage return

        $/n means newline

        $/t for tabulation

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326706980&siteId=291194637