EP04_Scripting_Reference (P9)

294 阅读21分钟

4.9 Instructions

4.9.1 Basic Instructions

The instructions that NSIS uses for scripting are sort of a cross between PHP and assembly. There are no real high level language constructs but the instructions themselves are (for the most part) high level, and you have handy string capability (i.e. you don't have to worry about concatenating strings, etc). You essentially have 25 registers (20 general purpose, 5 special purpose), and a stack.

4.9.1.1 Delete

Delete [/REBOOTOK] file

Delete file (which can be a file or wildcard, but should be specified with a full path) on the target system. If /REBOOTOK is specified and the file cannot be deleted then the file is deleted when the system reboots -- if the file will be deleted on a reboot, the reboot flag will be set. The error flag is set if files are found and cannot be deleted. The error flag is not set when trying to delete a file that does not exist.

删除目标系统上的文件(可以是文件或通配符,但应该使用完整路径指定)。

Delete $INSTDIR\somefile.dat

Warning: The /REBOOTOK switch requires administrator rights on Windows NT and later.

4.9.1.2 Exec

Exec command

Execute the specified program and continue immediately. Note that the file specified must exist on the target system, not the compiling system. $OUTDIR is used as the working directory. The error flag is set if the process could not be launched. Note, if the command could have spaces, you should put it in quotes to delimit it from parameters. e.g.: Exec '"$INSTDIR\command.exe" parameters'. If you don't put it in quotes it will not work on Windows 9x with or without parameters.

执行指定的程序并立即继续。

Exec '"$INSTDIR\someprogram.exe"'
Exec '"$INSTDIR\someprogram.exe" some parameters'

4.9.1.3 ExecShell

ExecShell [flags] action file [parameters] [SW_SHOWDEFAULT | SW_SHOWNORMAL | SW_SHOWMAXIMIZED | SW_SHOWMINIMIZED | SW_HIDE]

Execute the specified file using ShellExecuteEx. Note that action is usually "open", "print", etc, but can be an empty string to use the default action. Parameters and the show type are optional. $OUTDIR is used as the working directory. The error flag is set if the file could not be launched. Flags can be any combination of /ALLOWERRORUI, /DOENVSUBST and /INVOKEIDLIST.

使用ShellExecuteEx执行指定的文件。

ExecShell "open" "http://nsis.sf.net/"
ExecShell "" "$SysDir\Notepad.exe" "" SW_SHOWMAXIMIZED
ExecShell "print" "$INSTDIR\readme.txt"
ExecShell /INVOKEIDLIST "properties" "$TEMP"

4.9.1.4 ExecShellWait

ExecShellWait [flags] action file [parameters] [SW_SHOWDEFAULT | SW_SHOWNORMAL | SW_SHOWMAXIMIZED | SW_SHOWMINIMIZED | SW_HIDE]

Execute the specified file using ExecShell and wait for executed process to quit. It will only wait for executable files, not other file types nor URLs.

ExecShell执行指定的文件,并等待执行的进程退出。它将只等待可执行文件,而不是其他文件类型或url。

4.9.1.5 ExecWait

ExecWait command [user_var(exit code)]

Execute the specified program and wait for the executed process to quit. See Exec for more information. If no output variable is specified ExecWait sets the error flag if the program executed returns a nonzero error code, or if there is an error. If an output variable is specified, ExecWait sets the variable with the exit code (and only sets the error flag if an error occurs; if an error occurs the contents of the user variable are undefined). Note, if the command could have spaces, you should put it in quotes to delimit it from parameters. e.g.: ExecWait '"$INSTDIR\command.exe" parameters'. If you don't put it in quotes it will not work on Windows 9x with or without parameters.

执行指定的程序,等待执行的进程退出。

ExecWait '"$INSTDIR\someprogram.exe"'
ExecWait '"$INSTDIR\someprogram.exe"' $0
DetailPrint "some program returned $0"

4.9.1.6 File

File [/nonfatal] [/a] ([/r] [/x file|wildcard [...]] (file|wildcard) [...] | /oname=file.dat infile.dat)

Adds file(s) to be extracted to the current output path ($OUTDIR).

将要提取的文件添加到当前输出路径($OUTDIR)。

  • Note that the output file name is $OUTDIR\filename_portion_of_file.
  • Use /oname=X switch to change the output name. X may contain variables and can be a fully qualified path or a relative path in which case it will be appended to $OUTDIR set by SetOutPath. When using this switch, only one file can be specified. If the output name contains spaces, quote the entire parameter, including /oname, as shown in the examples below.
  • Wildcards are supported.
  • If the /r switch is used, matching files and directories are recursively searched for in subdirectories. If just one path segment is specified (e.g. File /r something), the current directory will be recursively searched. If more than one segment is specified (e.g. File /r something\*.*), the last path segment will be used as the matching condition and anything before it specifies which directory to search recursively. If a directory name matches, all of its contents is added recursively. Directory structure is preserved.
  • Use the /x switch to exclude files and directories.
  • If the /a switch is used, the attributes of the file(s) added will be preserved.
  • The File command sets the error flag if overwrite mode is set to 'try' and the file could not be overwritten, or if the overwrite mode is set to 'on' and the file could not be overwritten and the user selects ignore.
  • If the /nonfatal switch is used and no files are found, a warning will be issued instead of an error.
File something.exe
File /a something.exe
File *.exe
File /r *.dat
File /r data
File /oname=temp.dat somefile.ext
File /oname=$TEMP\temp.dat somefile.ext
File "/oname=$TEMP\name with spaces.dat" somefile.ext
File /nonfatal "a file that might not exist"
File /r /x CVS myproject\*.*
File /r /x *.res /x *.obj /x *.pch source\*.*

Note: When using the /r switch, both matching directories and files will be searched. This is always done with or without the use of wildcards, even if the given path perfectly matches one directory. That means, the following directory structure:

<DIR> something
  file.dat
  another.dat
<DIR> dir
  something
  <DIR> dir2
    file2.dat
<DIR> another
  <DIR> something
    readme.txt

with the following File usage:

File /r something

will match the directory named something in the root directory, the file named something in the directory named dir and the directory named something in the directory named another. To match only the directory named something in the root directory, use the following:

File /r something\*.*

When adding \*.*, it will be used as the matching condition and something will be used as the directory to search. When only something is specified, the current directory will be recursively searched for every file and directory named something and another\something will be matched.

4.9.1.7 Rename

Rename [/REBOOTOK] source_file dest_file

Rename source_file to dest_file. You can use it to move a file from anywhere on the system to anywhere else and you can move a directory to somewhere else on the same drive. The destination file must not exist or the move will fail (unless you are using /REBOOTOK). If /REBOOTOK is specified, and the file cannot be moved (if, for example, the destination exists), then the file is moved when the system reboots. If the file will be moved on a reboot, the reboot flag will be set. The error flag is set if the file cannot be renamed (and /REBOOTOK is not used) or if the source file does not exist.

source_file重命名为dest_file

If no absolute path is specified the current folder will be used. The current folder is the folder set using the last SetOutPath instruction. If you have not used SetOutPath the current folder is $EXEDIR.

如果没有指定绝对路径,则将使用当前文件夹。当前文件夹是使用最后一个SetOutPath指令设置的文件夹。如果你没有使用SetOutPath当前文件夹是$EXEDIR

Rename $INSTDIR\file.ext $INSTDIR\file.dat

Warning: The /REBOOTOK switch requires administrator rights on Windows NT and later.

Warning: Files cannot be moved from one drive to another if a reboot is required.

4.9.1.8 ReserveFile

ReserveFile [/nonfatal] [/r] [/x file|wildcard [...]] file [file...] | [/nonfatal] /plugin file.dll

Reserves a file in the data block for later use. Files are added to the compressed data block in the order they appear in the script. Functions, however, are not necessarily called in the order they appear in the script. Therefore, if you add a file in a function called early but put the function at the end of the script, all of the files added earlier will have to be decompressed to get to the required file. This process can take a long time if there a lot of files. .onInit is one such function. It is called at the very beginning, before anything else appears. If you put it at the very end of the script, extract some files in it and have lots of files added before it, the installer might take a very long time to load. This is where this command comes useful, allowing you to speed up the loading process by including the file at the top of the data block instead of letting NSIS seek all the way down to the bottom of the compressed data block.

在数据块中保留一个文件供以后使用。

Use /plugin to reserve a plugin in ${NSISDIR}\Plugins\*.

See File for more information about the parameters.

4.9.1.9 RMDir

RMDir [/r] [/REBOOTOK] directory_name

Remove the specified directory (fully qualified path with no wildcards). Without /r, the directory will only be removed if it is completely empty. If /r is specified the directory will be removed recursively, so all directories and files in the specified directory will be removed. If /REBOOTOK is specified, any file or directory which could not be removed during the process will be removed on reboot -- if any file or directory will be removed on a reboot, the reboot flag will be set. The error flag is set if any file or directory cannot be removed.

删除指定的目录(不带通配符的完全限定路径)。

RMDir $INSTDIR
RMDir $INSTDIR\data
RMDir /r /REBOOTOK $INSTDIR
RMDir /REBOOTOK $INSTDIR\DLLs

Note that the current working directory can not be deleted. The current working directory is set by SetOutPath. For example, the following example will not delete the directory.

注意,当前工作目录不能被删除。当前工作目录由SetOutPath设置。

SetOutPath $TEMP\dir
RMDir $TEMP\dir

The next example will succeed in deleting the directory.

SetOutPath $TEMP\dir
SetOutPath $TEMP
RMDir $TEMP\dir

Warning: Using RMDir /r $INSTDIR in the uninstaller is not safe. Though it is unlikely, the user might select to install to the root of the Program Files folder and this command would wipe out the entire Program Files folder, including all other installed programs! The user can also put other files in the installation folder and wouldn't expect them to get deleted along with the program. Solutions are available for easily uninstalling only files which were installed by the installer.

Warning: The /REBOOTOK switch requires administrator rights on Windows NT and later.

4.9.1.10 SetOutPath

SetOutPath outpath

Sets the output path ($OUTDIR) and creates it (recursively if necessary), if it does not exist. Must be a full pathname, usually is just $INSTDIR (you can specify $INSTDIR with a single "-" if you are lazy).

设置输出路径($OUTDIR),如果它不存在,则创建它(必要时递归)。

SetOutPath $INSTDIR
File program.exe

4.9.2 Registry, INI, File Instructions

In all of the below registry instructions use an empty string (just two quotes with nothing between them - "") as the key name to specify the default key which is shown as (Default) in regedit.exe.

Use SetRegView on 64-bit Windows to choose which registry view is used.

If a full path is not specified for any of the INI handling instructions, the Windows directory will be used.

4.9.2.1 DeleteINISec

DeleteINISec ini_filename section_name

Deletes the entire section [section_name] from ini_filename. If the section could not be removed from the ini file, the error flag is set. It does not set the error flag if the section could not be found.

WriteINIStr $TEMP\something.ini section1 something 123
WriteINIStr $TEMP\something.ini section1 somethingelse 1234
WriteINIStr $TEMP\something.ini section2 nsis true
DeleteINISec $TEMP\something.ini section1

4.9.2.2 DeleteINIStr

DeleteINIStr ini_filename section_name str_name

Deletes the string str_name from section [section_name] from ini_filename. If the string could not be removed from the ini file, the error flag is set. It does not set the error flag if the string could not be found.

WriteINIStr $TEMP\something.ini section1 something 123
WriteINIStr $TEMP\something.ini section1 somethingelse 1234
DeleteINIStr $TEMP\something.ini section1 somethingelse

4.9.2.3 DeleteRegKey

DeleteRegKey [/ifempty | /ifnosubkeys | /ifnovalues] root_key subkey

Deletes a registry key. If /ifempty is specified, the registry key will only be deleted if it has no subkeys and no values (otherwise, the whole registry tree will be removed). Valid values for root_key are listed under WriteRegStr. The error flag is set if the key could not be removed from the registry (or if it didn't exist to begin with).

DeleteRegKey HKLM "Software\My Company\My Software"
DeleteRegKey /ifempty HKLM "Software\A key that might have subkeys"

4.9.2.4 DeleteRegValue

DeleteRegValue root_key subkey key_name

Deletes a registry value. Valid values for root_key are listed under WriteRegStr. The error flag is set if the value could not be removed from the registry (or if it didn't exist to begin with).

DeleteRegValue HKLM "Software\My Company\My Software" "some value"

4.9.2.5 EnumRegKey

EnumRegKey user_var(output) root_key subkey index

Set user variable $x with the name of the 'index'th registry key in root_key \ Subkey. Valid values for root_key are listed under WriteRegStr. Returns an empty string if there are no more keys, and returns an empty string and sets the error flag if there is an error.

StrCpy $0 0
loop:
  EnumRegKey $1 HKLM Software $0
  StrCmp $1 "" done
  IntOp $0 $0 + 1
  MessageBox MB_YESNO|MB_ICONQUESTION "$1$\n$\nMore?" IDYES loop
done:

4.9.2.6 EnumRegValue

EnumRegValue user_var(output) root_key subkey index

Set user variable $x with the name of the 'index'th registry value in root_key \ Subkey. Valid values for root_key are listed under WriteRegStr. Returns an empty string and sets the error flag if there are no more values or if there is an error.

StrCpy $0 0
loop:
  ClearErrors
  EnumRegValue $1 HKLM Software\Microsoft\Windows\CurrentVersion $0
  IfErrors done
  IntOp $0 $0 + 1
  ReadRegStr $2 HKLM Software\Microsoft\Windows\CurrentVersion $1
  MessageBox MB_YESNO|MB_ICONQUESTION "$1 = $2$\n$\nMore?" IDYES loop
done:

4.9.2.7 ExpandEnvStrings

ExpandEnvStrings user_var(output) string

Expands environment variables in string into the user variable $x. If an environment variable doesn't exist, it will not be replaced. For example, if you use "%var%" and var doesn't exists, the result will be "%var%". If there is an error, the variable is set to empty, and the error flag is set.

ExpandEnvStrings $0 "WINDIR=%WINDIR%$\nTEMP=%TEMP%"

4.9.2.8 FlushINI

FlushINI ini_filename

Flushes the INI file's buffers. Windows 9x keeps all changes to the INI file in memory. This command causes the changes to be written to the disk immediately. Use it if you edit the INI manually, delete it, move it or copy it right after you change it with WriteINIStr, DeleteINISec or DeleteINStr.

WriteINIStr $TEMP\something.ini test test test
FlushINI $TEMP\something.ini
Delete $TEMP\something.ini

4.9.2.9 ReadEnvStr

ReadEnvStr user_var(output) name

Reads from the environment string "name" and sets the value into the user variable $x. If there is an error reading the string, the user variable is set to empty, and the error flag is set.

ReadEnvStr $0 WINDIR
ReadEnvStr $1 TEMP

4.9.2.10 ReadINIStr

ReadINIStr user_var(output) ini_filename section_name entry_name

Reads from entry_name in [section_name] of ini_filename and stores the value into user variable $x. The error flag will be set and $x will be assigned to an empty string if the entry is not found.

ReadINIStr $0 $INSTDIR\winamp.ini winamp outname

4.9.2.11 ReadRegDWORD

ReadRegDWORD user_var(output) root_key sub_key name

Reads a 32-bit DWORD from the registry into the user variable $x. Valid values for root_key are listed under WriteRegStr. The error flag will be set and $x will be set to an empty string ("" which is interpreted as 0 in math operations) if the DWORD is not present. If the value is present, but is not a DWORD, it will be read as a string and the error flag will be set.

ReadRegDWORD $0 HKLM Software\NSIS VersionBuild

4.9.2.12 ReadRegStr

ReadRegStr user_var(output) root_key sub_key name

Reads from the registry into the user variable $x. Valid values for root_key are listed under WriteRegStr. The error flag will be set and $x will be set to an empty string ("") if the string is not present. If the value is present, but is of type REG_DWORD, it will be read and converted to a string and the error flag will be set.

ReadRegStr $0 HKLM Software\NSIS ""
DetailPrint "NSIS is installed at: $0"

4.9.2.13 WriteINIStr

WriteINIStr ini_filename section_name entry_name value

Writes entry_name=value into [section_name] of ini_filename. The error flag is set if the string could not be written to the ini file.

WriteINIStr $TEMP\something.ini section1 something 123
WriteINIStr $TEMP\something.ini section1 somethingelse 1234
WriteINIStr $TEMP\something.ini section2 nsis true

4.9.2.14 WriteRegBin

WriteRegBin root_key subkey key_name valuedata

This command writes a block of binary data to the registry. Valid values for root_key are listed under WriteRegStr. Valuedata is in hexadecimal (e.g. DEADBEEF01223211151). The error flag is set if the binary data could not be written to the registry. If the registry key doesn't exist it will be created.

WriteRegBin HKLM "Software\My Company\My Software" "Binary Value" DEADBEEF01223211151

4.9.2.15 WriteRegNone

WriteRegNone root_key subkey key_name

Writes a value without data to the registry.

4.9.2.16 WriteRegDWORD

WriteRegDWORD root_key subkey key_name value

This command writes a DWORD (32-bit integer) to the registry (a user variable can be specified). Valid values for root_key are listed under WriteRegStr. The error flag is set if the dword could not be written to the registry. If the registry key doesn't exist it will be created.

WriteRegDWORD HKLM "Software\My Company\My Software" "DWORD Value" 0xDEADBEEF

4.9.2.17 WriteRegStr

WriteRegStr root_key subkey key_name value

Write a string to the registry. See WriteRegExpandStr for more details.

WriteRegStr HKLM "Software\My Company\My Software" "String Value" "dead beef"

4.9.2.18 WriteRegExpandStr

WriteRegExpandStr root_key subkey key_name value

Write a string to the registry. root_key must be one of:

  • 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
  • HKCR32 or HKCR64
  • HKCU32 or HKCU64
  • HKLM32 or HKLM64

If root_key is SHCTX or SHELL_CONTEXT, it will be replaced with HKLM if SetShellVarContext is set to all and with HKCU if SetShellVarContext is set to current.

The error flag is set if the string could not be written to the registry. The type of the string will be REG_SZ for WriteRegStr, or REG_EXPAND_STR for WriteRegExpandStr. If the registry key doesn't exist it will be created.

WriteRegExpandStr HKLM "Software\My Company\My Software" "Expand String Value" "%WINDIR%\notepad.exe"

4.9.2.19 WriteRegMultiStr

WriteRegMultiStr /REGEDIT5 root_key subkey key_name value

Writes a multi-string value. The /REGEDIT5 switch must be used and specifies that the data is in the hex format used by .reg files on Windows 2000 and later.

WriteRegMultiStr /REGEDIT5 HKCU "Software\NSIS\Test" "Multi Value" 66,00,6f,00,6f,00,00,00,62,00,61,00,72,00,00,00,00,00

4.9.2.20 SetRegView

SetRegView 32|64|default|lastused

Sets the registry view affected by registry commands (root keys with a 32/64 suffix are not affected). On 64-bit versions of Windows there are two views; one for 32-bit applications and one for 64-bit applications. By default, 32-bit applications running on 64-bit systems (WOW64) only have access to the 32-bit view. Using SetRegView 64 allows the installer to access keys in the 64-bit view of the registry. Registry operations will fail if the selected view is not supported by Windows.

Affects DeleteRegKey, DeleteRegValue, EnumRegKey, EnumRegValue, ReadRegDWORD, ReadRegStr, WriteRegBin, WriteRegDWORD, WriteRegStr and WriteRegExpandStr.

Does not affect InstallDirRegKey. Instead, the registry must be read using ReadRegStr in .onInit.

SetRegView 32
ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion ProgramFilesDir
DetailPrint $0 # prints C:\Program Files (x86)
!include x64.nsh
${If} ${RunningX64}
  SetRegView 64
  ReadRegStr $0 HKLM Software\Microsoft\Windows\CurrentVersion ProgramFilesDir
  DetailPrint $0 # prints C:\Program Files
${EndIf}
SetRegView Default

4.9.3 General Purpose Instructions

4.9.3.1 CallInstDLL

CallInstDLL dllfile function_name

Calls a function named function_name inside a NSIS extension DLL, a plug-in. See the example plugin for how to make one. Extension DLLs can access the stack and variables. Note: To automatically extract and call plug-in DLLs, use a plug-in command instead of CallInstDLL.

调用NSIS扩展DLL(插件)中名为function_name的函数。注意:要自动提取和调用插件dll,请使用插件命令而不是CallInstDLL

Push "a parameter"
Push "another parameter"
CallInstDLL $INSTDIR\somedll.dll somefunction

For easier plug-in handling, use the new plug-in call syntax.

4.9.3.2 CopyFiles

CopyFiles [/SILENT] [/FILESONLY] filespec_on_destsys destination_path [size_of_files_in_kb]

Copies files from the source to the destination on the installing system. Useful with $EXEDIR if you want to copy from installation media, or to copy from one place to another on the system. You might see a Windows status window of the copy operation if the operation takes a lot of time (to disable this, use /SILENT). The last parameter can be used to specify the size of the files that will be copied (in kilobytes), so that the installer can approximate the disk space requirements. On error, or if the user cancels the copy (only possible when /SILENT was omitted), the error flag is set. If /FILESONLY is specified, only files are copied.

将文件从源文件复制到安装系统上的目标文件。

Fully-qualified path names should always be used with this instruction. Using relative paths will have unpredictable results.

完全限定路径名应该总是与此指令一起使用。使用相对路径会产生不可预测的结果。

CreateDirectory $INSTDIR\backup
CopyFiles $INSTDIR\*.dat $INSTDIR\backup

4.9.3.3 CreateDirectory

CreateDirectory path_to_create

Creates (recursively if necessary) the specified directory. The error flag is set if the directory couldn't be created.

创建(必要时递归地)指定的目录。如果无法创建目录,则设置错误标志。

You should always specify an absolute path.

您应该始终指定一个绝对路径。

CreateDirectory $INSTDIR\some\directory

4.9.3.4 CreateShortcut

CreateShortcut [/NoWorkingDir] link.lnk target.file [parameters [icon.file [icon_index_number [start_options [keyboard_shortcut [description]]]]]]

Creates a shortcut 'link.lnk' that links to 'target.file', with optional parameters 'parameters'. You must specify an absolute path to the .lnk file. The icon used for the shortcut is 'icon.file,icon_index_number'; for default icon settings use empty strings for both icon.file and icon_index_number. start_options should be one of: SW_SHOWNORMAL, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, or an empty string. keyboard_shortcut should be in the form of 'flag|c' where flag can be a combination (using |) of: ALT, CONTROL, EXT, or SHIFT. c is the character to use (a-z, A-Z, 0-9, F1-F24, etc). Note that no spaces are allowed in this string. A good example is "ALT|CONTROL|F8". $OUTDIR is stored as the shortcut's working directory property. You can change it by using SetOutPath before creating the shortcut or use /NoWorkingDir if you don't need to set the working directory property. description should be the description of the shortcut, or comment as it is called under XP. The error flag is set if the shortcut cannot be created (i.e. either of the paths (link or target) does not exist, or some other error).

创建一个快捷方式“link.lnk”来链接到“target.file”,带有可选参数“parameters”。

CreateShortcut "$DESKTOP\My Program.lnk" "$INSTDIR\My Program.exe"
CreateDirectory "$SMPROGRAMS\My Company"
CreateShortcut "$SMPROGRAMS\My Company\My Program.lnk" "$INSTDIR\My Program.exe" \
  "some command line parameters" "$INSTDIR\My Program.exe" 2 SW_SHOWNORMAL \
  ALT|CONTROL|SHIFT|F5 "a description"

4.9.3.5 GetWinVer

GetWinVer user_var(output) Major|Minor|Build|ServicePack

Gets the Windows version as reported by GetVersionEx. WinVer.nsh is the preferred method for performing Windows version checks.

获取GetVersionEx报告的Windows版本。WinVer.nsh是执行Windows版本检查的首选方法。

GetWinVer $1 Build

4.9.3.6 GetDLLVersion

GetDLLVersion [/ProductVersion] filename user_var(high dword output) user_var(low dword output)

Gets the version information from the DLL (or any other executable containing version information) in "filename". Sets the user output variables with the high and low dwords of version information on success; on failure the outputs are empty and the error flag is set. The following example reads the DLL version and copies a human readable version of it into $0:

filename中的DLL(或包含版本信息的任何其他可执行文件)获取版本信息。

GetDllVersion "$INSTDIR\MyDLL.dll" $R0 $R1
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000FFFF
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000FFFF
StrCpy $0 "$R2.$R3.$R4.$R5"

4.9.3.7 GetDLLVersionLocal

GetDLLVersionLocal [/ProductVersion] localfilename user_var(high dword output) user_var(low dword output)

This is similar to GetDLLVersion, only it acts on the system building the installer (it actually compiles into two StrCpy commands). Sets the two output variables with the DLL version information of the DLL on the build system. Use !getdllversion if you need to use the values with VIProductVersion.

这类似于GetDLLVersion,只是它作用于系统构建安装程序(它实际上编译成两个StrCpy命令)。

4.9.3.8 GetFileTime

GetFileTime filename user_var(high dword output) user_var(low dword output)

Gets the last write time of "filename". Sets the user output variables with the high and low dwords of the FILETIME timestamp on success; on failure the outputs are empty and the error flag is set.

获取filename的最后一次写入时间。

4.9.3.9 GetFileTimeLocal

GetFileTimeLocal localfilename user_var(high dword output) user_var(low dword output)

This is similar to GetFileTime, only it acts on the system building the installer (it actually compiles into two StrCpy commands). Sets the two output variables with the file timestamp of the file on the build system.

这类似于GetFileTime,只是它作用于系统构建安装程序(它实际上编译成两个StrCpy命令)。

4.9.3.10 GetKnownFolderPath

GetKnownFolderPath user_var(output) knownfolderid

Get the path of a known folder. The error flag is set and the output variable is empty if the call fails or the knownfolderid guid is not available. This function is only able to resolve known folders on Windows Vista or higher.

获取一个已知文件夹的路径。

!include WinCore.nsh
!include LogicLib.nsh

Function .onInit
${If} $InstDir == ""
  GetKnownFolderPath $InstDir ${FOLDERID_UserProgramFiles} ; This exists on Win7+
  StrCmp $InstDir "" 0 +2 
  StrCpy $InstDir "$LocalAppData\Programs" ; Fallback directory
  StrCpy $InstDir "$InstDir\$(^Name)"
${EndIf}
FunctionEnd

4.9.3.11 GetFullPathName

GetFullPathName [/SHORT] user_var(output) path_or_file

Assign the full path of the file specified to user variable $x. If the path portion of the parameter is not found, the error flag will be set and $x will be empty. If /SHORT is specified, the path is converted to the short filename form. However, if /SHORT is not specified, the path isn't converted to its long filename form. To get the long filename, call GetLongPathName using the System plug-in. Note that GetLongPathName is only available on Windows 98, Windows 2000 and above.

将文件的完整路径指定给用户变量$x

StrCpy $INSTDIR $PROGRAMFILES\NSIS
SetOutPath $INSTDIR
GetFullPathName $0 ..
DetailPrint $0 # will print C:\Program Files
GetFullPathName /SHORT $0 $INSTDIR
DetailPrint $0 # will print C:\Progra~1\NSIS
StrCpy $0 C:\Progra~1\NSIS
System::Call 'kernel32::GetLongPathName(t r0, t .r1, i ${NSIS_MAX_STRLEN}) i .r2'
StrCmp $2 error +2
StrCpy $0 $1
DetailPrint $0 # will print C:\Program Files\NSIS, where supported

4.9.3.12 GetTempFileName

GetTempFileName user_var(output) [base_dir]

Assign to the user variable $x, the name of a temporary file. The file will be created for you and it will be empty. The name of the temporary file is guaranteed to be unique. If to want the temporary file to be created in another directory other than the Windows temp directory, specify a base_dir. You should Delete the file when you are done with it.

给用户变量$x赋值,它是一个临时文件的名称。

GetTempFileName $0
File /oname=$0 something.dat
# do something with something.dat
Delete $0

4.9.3.13 SearchPath

SearchPath user_var(output) filename

Assign to the user variable $x, the full path of the file named by the second parameter. The error flag will be set and $x will be empty if the file cannot be found. Uses SearchPath() to search the system paths for the file.

赋值给用户变量$x,即由第二个参数命名的文件的完整路径。

4.9.3.14 SetFileAttributes

SetFileAttributes filename attribute1|attribute2|...

Sets the file attributes of 'filename'. Valid attributes can be combined with | and are:

设置filename的文件属性。

  • NORMAL or FILE_ATTRIBUTE_NORMAL (you can use 0 to abbreviate this)
  • ARCHIVE or FILE_ATTRIBUTE_ARCHIVE
  • HIDDEN or FILE_ATTRIBUTE_HIDDEN
  • OFFLINE or FILE_ATTRIBUTE_OFFLINE
  • READONLY or FILE_ATTRIBUTE_READONLY
  • SYSTEM or FILE_ATTRIBUTE_SYSTEM
  • TEMPORARY or FILE_ATTRIBUTE_TEMPORARY
  • NOTINDEXED or FILE_ATTRIBUTE_NOT_CONTENT_INDEXED

The error flag will be set if the file's attributes cannot be set (i.e. the file doesn't exist, or you don't have the right permissions). You can only set attributes. It's not possible to unset them. If you want to remove an attribute use NORMAL. This way all attributes are erased. This command doesn't support wildcards.

4.9.3.15 RegDLL

RegDLL dllfile [entrypoint_name]

Loads the specified DLL and calls DllRegisterServer (or entrypoint_name if specified). The error flag is set if an error occurs (i.e. it can't load the DLL, initialize OLE, find the entry point, or the function returned anything other than ERROR_SUCCESS (=0)).

加载指定的DLL并调用DllRegisterServer(或entrypoint_name如果指定)。

Use SetOutPath to set the current directory for DLLs that depend on other DLLs that are now in the path or in the Windows directory. For example, if foo.dll depends on bar.dll which is located in $INSTDIR use:

SetOutPath $INSTDIR
RegDLL $INSTDIR\foo.dll

4.9.3.16 UnRegDLL

UnRegDLL dllfile

Loads the specified DLL and calls DllUnregisterServer. The error flag is set if an error occurs (i.e. it can't load the DLL, initialize OLE, find the entry point, or the function returned anything other than ERROR_SUCCESS (=0)).

加载指定的DLL并调用DllUnregisterServer

4.9.4 Flow Control Instructions

4.9.4.1 Abort

Abort [user_message]

Cancels the install, stops execution of script, and displays user_message in the status display. Note: you can use this from Callback functions to do special things. Page callbacks also uses Abort for special purposes.

取消安装,停止执行脚本,并在状态显示中显示user_message

Abort
Abort "can't install"

4.9.4.2 Call

Call function_name | :label_name | user_var(input)

Calls the function named function_name, the label named label_name, or a variable that specifies an address. An address is returned by GetCurrentAddress, GetFunctionAddress or GetLabelAddress. A call returns when it encounters a Return instruction. Sections and functions are automatically ended with a Return instruction. Uninstall functions cannot be called from installer functions and sections, and vice-versa.

调用名为function_name的函数,名为label_name的标签,或指定地址的变量。

Function func
  Call :label
  DetailPrint "#1: This will only appear 1 time."
label:
  DetailPrint "#2: This will appear before and after message #1."
  Call :.global_label
FunctionEnd

Section
  Call func
  Return

.global_label:
  DetailPrint "#3: The global label was called"
SectionEnd

4.9.4.3 ClearErrors

Clears the error flag.

清除错误标志。

ClearErrors
IfErrors 0 +2
  MessageBox MB_OK "this message box will never show"

4.9.4.4 GetCurrentAddress

GetCurrentAddress user_var(output)

Gets the address of the current instruction (the GetCurrentAddress) and stores it in the output user variable. This user variable then can be passed to Call or Goto.

获取当前指令的地址(GetCurrentAddress)并将其存储在输出用户变量中。

Function func
  DetailPrint "function"
  IntOp $0 $0 + 2 ; Calculate the address after of the instruction after "Goto callFunc" in the Section
  Call $0
  DetailPrint "function end"
FunctionEnd

Section
  DetailPrint "section"
  GetCurrentAddress $0
  Goto callFunc

  DetailPrint "back in section"
  Return

callFunc:
  Call func
  DetailPrint "section end"
SectionEnd

4.9.4.5 GetFunctionAddress

GetFunctionAddress user_var(output) function_name

Gets the address of the function and stores it in the output user variable. This user variable then can be passed to Call or Goto. Note that if you Goto an address which is the output of GetFunctionAddress, your function will never be returned to (when the function you Goto'd to returns, you return instantly).

获取函数的地址并将其存储在输出用户变量中。

Function func
  DetailPrint "function"
FunctionEnd

Section
  GetFunctionAddress $0 func
  Call $0
SectionEnd

4.9.4.6 GetLabelAddress

GetLabelAddress user_var(output) label

Gets the address of the label and stores it in the output user variable. This user variable then can be passed to Call or Goto. Note that you may only call this with labels accessible from your function, but you can call it from anywhere (which is potentially dangerous). Note that if you Call the output of GetLabelAddress, code will be executed until it Return's (explicitly or implicitly at the end of a function), and then you will be returned to the statement after the Call.

获取标签的地址并将其存储在输出用户变量中。

label:
DetailPrint "label"
GetLabelAddress $0 label
IntOp $0 $0 + 4
Goto $0
DetailPrint "done"

4.9.4.7 Goto

Goto label_to_jump_to | +offset| -offset| user_var(target)

If label is specified, goto the label 'label_to_jump_to:'.

If +offset or -offset is specified, jump is relative by offset instructions. Goto +1 goes to the next instruction, Goto -1 goes to the previous instruction, etc.

If a user variable is specified, jumps to absolute address (generally you will want to get this value from a function like GetLabelAddress). Compiler flag commands and SectionIn aren't instructions so jumping over them has no effect.

Goto label
Goto +2
Goto -2
Goto $0

4.9.4.8 IfAbort

IfAbort label_to_goto_if_abort [label_to_goto_if_no_abort]

Will "return" true if the installation has been aborted. This can happen if the user chose abort on a file that failed to create (or overwrite) or if the user aborted by hand. This function can only be called from the leave function of the instfiles page.

如果安装被中止,将“返回”true。

Page instfiles "" "" instfilesLeave

Function instfilesLeave
  IfAbort 0 +2
    MessageBox MB_OK "user aborted"
FunctionEnd

4.9.4.9 IfErrors

IfErrors jumpto_iferror [jumpto_ifnoerror]

Checks and clears the error flag, and if it is set, it will goto jumpto_iferror, otherwise it will goto jumpto_ifnoerror. The error flag is set by other instructions when a recoverable error (such as trying to delete a file that is in use) occurs.

检查并清除错误标志,如果它被设置,它将转到jumpto_iferror,否则它将转到jumpto_ifnoerror

ClearErrors
File file.dat
IfErrors 0 +2
  Call ErrorHandler

4.9.4.10 IfFileExists

IfFileExists file_to_check_for jump_if_present [jump_otherwise]

Checks for existence of file(s) file_to_check_for (which can be a wildcard, or a directory), and Gotos jump_if_present if the file exists, otherwise Gotos jump_otherwise. If you want to check to see if a file is a directory, use IfFileExists DIRECTORY\*.*

检查文件是否存在file_to_check_for(可以是一个通配符,或一个目录),如果文件存在,则跳转jump_if_present,否则跳转jump_otherwise

IfFileExists $WINDIR\notepad.exe 0 +2
  MessageBox MB_OK "notepad is installed"

4.9.4.11 IfRebootFlag

IfRebootFlag jump_if_set [jump_if_not_set]

Checks the reboot flag, and jumps to jump_if_set if the reboot flag is set, otherwise jumps to jump_if_not_set. The reboot flag can be set by Delete and Rename, or manually with SetRebootFlag.

检查reboot标志,如果设置了reboot标志,则跳转到jump_if_set,否则跳转到jump_if_not_set

IfRebootFlag 0 noreboot
  MessageBox MB_YESNO "A reboot is required to finish the installation. Do you wish to reboot now?" IDNO noreboot
    Reboot
noreboot:

4.9.4.12 IfSilent

IfSilent jump_if_silent [jump_if_not]

Checks the silent flag, and jumps to jump_if_silent if the installer is silent, otherwise jumps to jump_if_not. The silent flag can be set by SilentInstall, SilentUninstall, SetSilent and by the user passing /S on the command line.

检查静默标志,如果安装程序是静默的,则跳转到jump_if_silent,否则跳转到jump_if_not

IfSilent +2
  ExecWait '"$INSTDIR\nonsilentprogram.exe"'

4.9.4.13 IfShellVarContextAll

IfShellVarContextAll jump_if_true [jump_if_false]

Checks if SetShellVarContext is set to all.

检查SetShellVarContext是否设置为all。

4.9.4.14 IfRtlLanguage

IfRtlLanguage jump_if_true [jump_if_false]

Checks if active language is a RTL language.

检查活动语言是否为RTL语言。

Warning: Do not call this in [un].onInit because the language file has not been fully initialized.

4.9.4.15 IntCmp

IntCmp val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]

Compares two integers val1 and val2. If val1 and val2 are equal, Gotos jump_if_equal, otherwise if val1 < val2, Gotos jump_if_val1_less, otherwise if val1 > val2, Gotos jump_if_val1_more.

比较两个整数val1val2

IntCmp $0 5 is5 lessthan5 morethan5
is5:
  DetailPrint "$$0 == 5"
  Goto done
lessthan5:
  DetailPrint "$$0 < 5"
  Goto done
morethan5:
  DetailPrint "$$0 > 5"
  Goto done
done:

4.9.4.16 IntCmpU

IntCmpU val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]

Same as IntCmp, but treats the values as unsigned integers.

IntCmp相同,但将值视为无符号整数。

4.9.4.17 Int64Cmp

Int64Cmp val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]

Same as IntCmp, but treats the values as 64-bit integers.

IntCmp相同,但将值视为64位整数。

This function is only available when building a 64-bit installer.

4.9.4.18 Int64CmpU

Int64CmpU val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]

Same as IntCmp, but treats the values as 64-bit unsigned integers.

IntCmp相同,但将值视为64位无符号整数。

This function is only available when building a 64-bit installer.

4.9.4.19 IntPtrCmp

IntPtrCmp val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]

Same as IntCmp, but treats the values as pointer sized integers.

IntCmp相同,但将值视为指针大小的整数。

4.9.4.20 IntPtrCmpU

IntPtrCmpU val1 val2 jump_if_equal [jump_if_val1_less] [jump_if_val1_more]

Same as IntCmp, but treats the values as pointer sized unsigned integers.

IntCmp相同,但将值视为指针大小的无符号整数。

4.9.4.21 MessageBox

MessageBox mb_option_list messagebox_text [/SD return] [return_check jumpto [return_check_2 jumpto_2]]

Displays a MessageBox containing the text "messagebox_text". mb_option_list must be one or more of the following, delimited by |s (e.g. MB_YESNO|MB_ICONSTOP).

显示一个包含文本“messagebox_text”的消息框。

  • MB_OK - Display with an OK button
  • MB_OKCANCEL - Display with an OK and a cancel button
  • MB_ABORTRETRYIGNORE - Display with abort, retry, ignore buttons
  • MB_RETRYCANCEL - Display with retry and cancel buttons
  • MB_YESNO - Display with yes and no buttons
  • MB_YESNOCANCEL - Display with yes, no, cancel buttons
  • MB_ICONEXCLAMATION - Display with exclamation icon
  • MB_ICONINFORMATION - Display with information icon
  • MB_ICONQUESTION - Display with question mark icon
  • MB_ICONSTOP - Display with stop icon
  • MB_USERICON - Display with installer's icon
  • MB_TOPMOST - Make messagebox topmost
  • MB_SETFOREGROUND - Set foreground
  • MB_RIGHT - Right align text
  • MB_RTLREADING - RTL reading order
  • MB_DEFBUTTON1 - Button 1 is default
  • MB_DEFBUTTON2 - Button 2 is default
  • MB_DEFBUTTON3 - Button 3 is default
  • MB_DEFBUTTON4 - Button 4 is default

Return_check can be 0 (or empty, or left off), or one of the following:

  • IDABORT - Abort button
  • IDCANCEL - Cancel button
  • IDIGNORE - Ignore button
  • IDNO - No button
  • IDOK - OK button
  • IDRETRY - Retry button
  • IDYES - Yes button

If the return value of the MessageBox is return_check, the installer will Goto jumpto.

Use the /SD parameter with one of the return_check values above to specify the option that will be used when the installer is silent. See section 4.12 for more information.

MessageBox MB_OK "simple message box"
MessageBox MB_YESNO "is it true?" IDYES true IDNO false
true:
  DetailPrint "it's true!"
  Goto next
false:
  DetailPrint "it's false"
next:
MessageBox MB_YESNO "is it true? (defaults to yes on silent installations)" /SD IDYES IDNO false2
  DetailPrint "it's true (or silent)!"
  Goto next2
false2:
  DetailPrint "it's false"
next2:

4.9.4.22 Return

Returns from a function or section.

从函数或条款返回。

Function func
  StrCmp $0 "return now" 0 +2
    Return
  # do stuff
FunctionEnd

Section
  Call func
  ;"Return" will return here
SectionEnd

4.9.4.23 Quit

Causes the installer to exit as soon as possible. After Quit is called, the installer will exit (no callback functions will get a chance to run).

使安装程序尽快退出。

4.9.4.24 SetErrors

Sets the error flag.

设置错误标志。

SetErrors
IfErrors 0 +2
  MessageBox MB_OK "this message box will always show"

4.9.4.25 StrCmp

StrCmp str1 str2 jump_if_equal [jump_if_not_equal]

Compares (case insensitively) str1 to str2. If str1 and str2 are equal, Gotos jump_if_equal, otherwise Gotos jump_if_not_equal.

比较(不区分大小写)“str1”、“str2”。

StrCmp $0 "a string" 0 +3
  DetailPrint '$$0 == "a string"'
  Goto +2
  DetailPrint '$$0 != "a string"'

4.9.4.26 StrCmpS

StrCmpS str1 str2 jump_if_equal [jump_if_not_equal]

Same as StrCmp, but case sensitive.

StrCmp相同,但区分大小写。

4.9.5 File Instructions

4.9.5.1 FileClose

FileClose handle

Closes a file handle opened with FileOpen.

关闭用FileOpen打开的文件句柄。

4.9.5.2 FileOpen

FileOpen user_var(handle output) filename openmode

Opens a file named "filename" and sets the handle output variable with the handle. The openmode should be one of "r" (read) "w" (write, all contents of file are destroyed) or "a" (append, meaning opened for both read and write, contents preserved). In all open modes, the file pointer is placed at the beginning of the file. If the file cannot be opened the handle output is set to empty and the error flag is set.

打开一个名为filename的文件,并用句柄设置句柄输出变量。

If no absolute path is specified the current folder will be used. The current folder is the folder set using the last SetOutPath instruction. If you have not used SetOutPath the current folder is $EXEDIR.

如果没有指定绝对路径,则将使用当前文件夹。当前文件夹是使用最后一个SetOutPath指令设置的文件夹。如果你没有使用SetOutPath当前文件夹是$EXEDIR

FileOpen $0 $INSTDIR\file.dat r
FileClose $0

4.9.5.3 FileRead

FileRead handle user_var(output) [maxlen]

Reads a string (ANSI characters) from a file opened with FileOpen. The string is read until either a newline (or carriage return newline pair) occurs, or until a null byte is read, or until maxlen is met (if specified). By default, strings are limited to 1024 characters (a special build with larger NSIS_MAX_STRLEN can be compiled or downloaded). If the end of file is reached and no more data is available, the output string will be empty and the error flag will be set.

从使用FileOpen打开的文件中读取字符串(ANSI字符)。

Unicode: DBCS text is supported but conversion output is limited to UCS-2/BMP, surrogate pairs are not supported. The system default ANSI codepage (ACP) is used during the conversion.

ClearErrors
FileOpen $0 $INSTDIR\file.dat r
IfErrors done
FileRead $0 $1
DetailPrint $1
FileClose $0
done:

4.9.5.4 FileReadUTF16LE

FileReadUTF16LE handle user_var(output) [maxlen]

This function is only available when building a Unicode installer.

Reads a string (UTF-16LE characters) from a file opened with FileOpen. The string is read until either a newline (or carriage return newline pair) occurs, or until a null wide-character is read, or until maxlen is met (if specified). By default, strings are limited to 1024 characters (a special build with larger NSIS_MAX_STRLEN can be compiled or downloaded). If the end of file is reached and no more data is available, the output string will be empty and the error flag will be set. If present, the BOM at the start of the file is skipped.

从使用FileOpen打开的文件中读取字符串(UTF-16LE字符)。

ClearErrors
FileOpen $0 $INSTDIR\file.dat r
IfErrors done
FileReadUTF16LE $0 $1
DetailPrint $1
FileClose $0
done:

4.9.5.5 FileReadByte

FileReadByte handle user_var(output)

Reads a byte from a file opened with FileOpen. The byte is stored in the output as an integer (0-255). If the end of file is reached and no more data is available, the output will be empty and the error flag will be set.

从使用FileOpen打开的文件中读取一个字节。

ClearErrors
FileOpen $0 $INSTDIR\file.dat r
IfErrors done
FileReadByte $0 $1
FileReadByte $0 $2
DetailPrint "$1 $2"
FileClose $0
done:

4.9.5.6 FileReadWord

FileReadWord handle user_var(output)

This function is only available when building a Unicode installer.

此函数仅在构建Unicode安装程序时可用。

Reads a word (2-bytes) from a file opened with FileOpen. The word is stored in the output as an integer (0-65535). If the end of file is reached and no more data is available, the output will be empty and the error flag will be set.

从使用FileOpen打开的文件中读取一个字(2字节)。

ClearErrors
FileOpen $0 $INSTDIR\file.dat r
IfErrors done
FileReadWord $0 $1
FileReadWord $0 $2
DetailPrint "$1 $2"
FileClose $0
done:

4.9.5.7 FileSeek

FileSeek handle offset [mode] [user_var(new position)]

Seeks a file opened with FileOpen. If mode is omitted or specified as SET, the file is positioned to "offset", relative to the beginning of the file. If mode is specified as CUR, then the file is positioned to "offset", relative to the current file position. If mode is specified as END, then the file is positioned to "offset", relative to the end of the file. If the final parameter "new position" is specified, the new file position will be stored in that variable.

寻找用FileOpen打开的文件。

ClearErrors
FileOpen $0 $INSTDIR\file.dat r
IfErrors done
FileSeek $0 -5 END
FileRead $0 $1
DetailPrint $1
FileClose $0
done:

4.9.5.8 FileWrite

FileWrite handle string

Writes an ANSI string to a file opened with FileOpen. If an error occurs writing, the error flag will be set.

将ANSI字符串写入使用FileOpen打开的文件。如果写入时发生错误,将设置错误标志。

(If you are building a Unicode installer, the function converts the string to ANSI/MBCS. The system default ANSI codepage (ACP) is used during the conversion)

ClearErrors
FileOpen $0 $INSTDIR\file.dat w
IfErrors done
FileWrite $0 "some text"
FileClose $0
done:

4.9.5.9 FileWriteUTF16LE

FileWriteUTF16LE [/BOM] handle string

This function is only available when building a Unicode installer.

此函数仅在构建Unicode安装程序时可用。

Writes a Unicode (UTF-16LE) string to a file opened with FileOpen. If an error occurs, the error flag will be set. A BOM can be added to empty files with /BOM.

将Unicode(UTF-16LE)字符串写入使用FileOpen打开的文件。如果发生错误,将设置错误标志。

ClearErrors
FileOpen $0 $INSTDIR\file.dat w
IfErrors done
FileWriteUTF16LE $0 "some text"
FileClose $0
done:

4.9.5.10 FileWriteByte

FileWriteByte handle string

Writes the integer interpretation of 'string' to a file opened with FileOpen. The error flag is set if an error occurs while writing. The following code writes a "Carriage Return / Line Feed" pair to the file.

将“string”的整数解释写入使用FileOpen打开的文件。如果写入时发生错误,则设置错误标志。

FileWriteByte file_handle "13"
FileWriteByte file_handle "10"

Note that only the low byte of the integer is used, i.e. writing 256 is the same as writing 0, etc.

4.9.5.11 FileWriteWord

FileWriteWord handle string

This function is only available when building a Unicode installer.

此函数仅在构建Unicode安装程序时可用。

Writes the integer interpretation of 'string' as a WORD (2-bytes, range: 0-65535) to a file opened with FileOpen. The error flag is set if an error occurs while writing. The following code writes a "Carriage Return / Line Feed" pair to the file.

将“string”的整数解释作为WORD(2字节,范围:0-65535)写入使用FileOpen打开的文件。如果写入时发生错误,则设置错误标志。

FileWriteWord file_handle "13"
FileWriteWord file_handle "10"

Note that only the low WORD of the integer is used, i.e. writing 65536 is the same as writing 0, etc.

4.9.5.12 FindClose

FindClose handle

Closes a search opened with FindFirst.

关闭使用FindFirst打开的搜索。

4.9.5.13 FindFirst

FindFirst user_var(handle output) user_var(filename output) filespec

Performs a search for 'filespec', placing the first file found in filename_output (a user variable). It also puts the handle of the search into handle_output (also a user variable). If no files are found, both outputs are set to empty and the error flag is set. FindClose must be used to close the handle. Note that the filename output is without path.

执行filespec搜索,将找到的第一个文件放在filename_output(一个用户变量)中。它还将搜索句柄放入handle_output(也是一个用户变量)。如果没有找到文件,则将两个输出都设置为空并设置错误标志。FindClose必须用于关闭句柄。

FindFirst $0 $1 $INSTDIR\*.txt
loop:
  StrCmp $1 "" done
  DetailPrint $1
  FindNext $0 $1
  Goto loop
done:
FindClose $0

4.9.5.14 FindNext

FindNext handle user_var(filename_output)

Continues a search began with FindFirst. handle should be the handle_output_variable returned by FindFirst. If the search is completed (there are no more files), filename_output is set to empty and the error flag is set. Note that the filename output is without path.

继续以FindFirst开始的搜索。

4.9.6 Uninstaller Instructions

4.9.6.1 WriteUninstaller

WriteUninstaller [Path\]exename.exe

Writes the uninstaller to the filename (and optionally path) specified. Only valid from within an install section or function and requires that you have an uninstall section in your script. You can call this one or more times to write out one or more copies of the uninstaller.

将卸载程序写入指定的filename(以及可选的路径)。

WriteUninstaller $INSTDIR\uninstaller.exe

4.9.7 Miscellaneous Instructions

4.9.7.1 GetErrorLevel

GetErrorLevel user_var(error level output)

Returns the last error level set by SetErrorLevel or -1 if it has never been set.

返回由SetErrorLevel设置的最后一个错误级别,如果没有设置,则返回-1。

GetErrorLevel $0
IntOp $0 $0 + 1
SetErrorLevel $0

4.9.7.2 GetInstDirError

GetInstDirError user_var(error output)

Use in the leave function of a directory page. Reads the flag set if 'DirVerify leave' is used. Possible values:

在目录页的leave-function中使用。

  • 0: No error
  • 1: Invalid installation directory
  • 2: Not enough space on installation drive
!include LogicLib.nsh
PageEx directory
  DirVerify leave
  PageCallbacks "" "" dirLeave
PageExEnd

Function dirLeave
  GetInstDirError $0
  ${Switch} $0
    ${Case} 0
      MessageBox MB_OK "valid installation directory"
      ${Break}
    ${Case} 1
      MessageBox MB_OK "invalid installation directory!"
      Abort
      ${Break}
    ${Case} 2
      MessageBox MB_OK "not enough free space!"
      Abort
      ${Break}
  ${EndSwitch}
FunctionEnd

4.9.7.3 InitPluginsDir

Initializes the plug-ins dir ($PLUGINSDIR) if not already initialized.

如果尚未初始化,则初始化插件目录($PLUGINSDIR)。

InitPluginsDir
File /oname=$PLUGINSDIR\image.bmp image.bmp

4.9.7.4 Nop

Does nothing.

什么也不做。

4.9.7.5 SetErrorLevel

SetErrorLevel error_level

Sets the error level of the installer or uninstaller to error_level. See Error Levels for more information.

设置安装程序或卸载程序的错误级别为error_level

IfRebootFlag 0 +2
  SetErrorLevel 4

Warning: -1 is reserved for internal use. Negative numbers should be avoided for compatibility with batch scripts.

4.9.7.6 SetShellVarContext

SetShellVarContext current|all|lastused

Sets the context of $SMPROGRAMS and other shell folders. If set to 'current' (the default), the current user's shell folders are used. If set to 'all', the 'all users' shell folder is used. The all users folder may not be supported on all OSes. If the all users folder is not found, the current user folder will be used. Please take into consideration that a "normal user" has no rights to write in the all users area. Only admins have full access rights to the all users area. You can check this by using the UserInfo plug-in. See Contrib\UserInfo\UserInfo.nsi for an example.

设置$SMPROGRAMS和其他shell文件夹的上下文。

Note that, if used in installer code, this will only affect the installer, and if used in uninstaller code, this will only affect the uninstaller. To affect both, it needs to be used in both.

注意,如果在安装程序代码中使用,这将只影响安装程序,如果在卸载程序代码中使用,这将只影响卸载程序。为了影响两者,它需要在两者中都使用。

SetShellVarContext current
StrCpy $0 $DESKTOP
SetShellVarContext all
StrCpy $1 $DESKTOP
MessageBox MB_OK $0$\n$1

4.9.7.7 Sleep

Sleep sleeptime_in_ms

Pauses execution in the installer for sleeptime_in_ms milliseconds. sleeptime_in_ms can be a variable, e.g. "$0" or a number, i.e. "4321".

在安装程序中暂停执行sleeptime_in_ms milliseconds

DetailPrint "sleeping..."
Sleep 3000
DetailPrint "back to work"

4.9.8 String Manipulation Instructions

4.9.8.1 StrCpy

StrCpy user_var(destination) str [maxlen] [start_offset]

Sets the user variable $x with str. str can contain variables (including the user variable being set (concatenating strings this way is possible, etc)). If maxlen is specified, the string will be a maximum of maxlen characters (if maxlen is negative, the string will be truncated abs(maxlen) characters from the end). If start_offset is specified, the source is offset by it (if start_offset is negative, it will start abs(start_offset) from the end of the string).

str设置用户变量$x

StrCpy $0 "a string" # = "a string"
StrCpy $0 "a string" 3 # = "a s"
StrCpy $0 "a string" -1 # = "a strin"
StrCpy $0 "a string" "" 2 # = "string"
StrCpy $0 "a string" "" -3 # = "ing"
StrCpy $0 "a string" 3 -4 # = "rin"
StrCpy $0 "$0$0" # = "rinrin"

4.9.8.2 StrLen

StrLen user_var(length output) str

Sets user variable $x to the length of str.

设置用户变量$xstr的长度。

StrLen $0 "123456" # = 6

4.9.9 Stack Support

The stack is a temporary storage area useful for saving the state of registers/variables and for communicating with functions and plug-ins. See Wikipedia for a general introduction to stacks.

4.9.9.1 Exch

Exch [user_var | stack_index]

When no parameter is specified, exchanges the top two elements of the stack. When a parameter is specified and is a user variable, exchanges the top element of the stack with the parameter. When a parameter is specified and is a positive integer, Exch will swap the item on the top of the stack with the item that is specified by the offset from the top of the stack in the parameter. If there are not enough items on the stack to accomplish the exchange, a fatal error will occur (to help you debug your code :).

**当没有指定参数时,交换堆栈顶部的两个元素。当指定了一个参数并且是一个用户变量时,将堆栈的顶部元素与该参数交换。

Push 1
Push 2
Exch
Pop $0 # = 1
Push 1
Push 2
Push 3
Exch 2
Pop $0 # = 1
StrCpy $0 1
Push 2
Exch $0 # = 2
Pop $1 # = 1

4.9.9.2 Pop

Pop user_var(out)

Pops a string off of the stack into user variable $x. If the stack is empty, the error flag will be set.

从堆栈中弹出一个字符串到用户变量$x

Push 1
Pop $0 # = 1

4.9.9.3 Push

Push string

Pushes a string onto the stack. The string can then be Pop'ed off of the stack.

将一个字符串压入堆栈。然后该字符串可以从堆栈中弹出。

Push "a string"

4.9.10 Integer Support

4.9.10.1 IntFmt

IntFmt user_var(output) format numberstring

Formats the number in "numberstring" using the format "format", and sets the output to user variable $x. The format string supports the same syntax as wsprintf except that the I[32|64] length fields and the p type are not supported. Example format strings include "%08X" and "%u".

使用格式"format"格式化"numberstring"中的数字,并将输出设置为用户变量$x

IntFmt $0 "0x%08X" 195948557
IntFmt $1 "%c" 0x41

4.9.10.2 Int64Fmt

Int64Fmt user_var(output) format numberstring

Supports the I and I64 length fields and the p type in addition to the syntax supported by IntFmt.

除了IntFmt支持的语法外,还支持II64长度字段和p类型。

This function is only available when building a 64-bit installer.

此函数仅在构建64位安装程序时可用。

Int64Fmt $0 "%I64x" 244837743786702

4.9.10.3 IntOp

IntOp user_var(output) value1 OP [value2]

Combines value1 and (depending on OP) value2 into the specified user variable (user_var). OP is defined as one of the following:

组合value1value2(取决于OP)到指定的用户变量(user_var)中。

  • + ADDs value1 and value2
  • - SUBTRACTs value2 from value1
  • * MULTIPLIEs value1 and value2
  • / DIVIDEs value1 by value2
  • % MODULUSs value1 by value2
  • | BINARY ORs value1 and value2
  • & BINARY ANDs value1 and value2
  • ^ BINARY XORs value1 and value2
  • << LEFT SHIFTs value1 by value2
  • >> ARITHMETIC RIGHT SHIFTs value1 by value2
  • >>> LOGICALLY RIGHT SHIFTs value1 by value2
  • ~ BITWISE NEGATEs value1 (i.e. 7 becomes 4294967288)
  • ! LOGICALLY NEGATEs value1 (i.e. 7 becomes 0)
  • || LOGICALLY ORs value1 and value2
  • && LOGICALLY ANDs value1 and value2
IntOp $0 1 + 1
IntOp $0 $0 + 1
IntOp $0 $0 << 2
IntOp $0 $0 ~
IntOp $0 $0 & 0xF

4.9.10.4 IntPtrOp

IntPtrOp user_var(output) value1 OP [value2]

Combines value1 and (depending on OP) value2 into the specified user variable (user_var). OP is the same list of operators as supported by IntOp.

组合value1value2(取决于OP)到指定的用户变量(user_var)中。

IntPtrOp $FieldAddress $MyBuffer + $FieldOffset

4.9.11 Reboot Instructions

4.9.11.1 Reboot

Reboots the computer. Be careful with this one. If it fails, .onRebootFailed is called. In any case, this instruction never returns, just like Quit.

重新启动电脑。

MessageBox MB_YESNO|MB_ICONQUESTION "Do you wish to reboot the system?" IDNO +2
  Reboot

4.9.11.2 SetRebootFlag

SetRebootFlag true|false

Sets the reboot flag to either true or false. The flag's value can be read using IfRebootFlag.

将重启标志设置为true或false。该标志的值可以使用IfRebootFlag来读取。

SetRebootFlag true
IfRebootFlag 0 +2
  MessageBox MB_OK "this message box will always show"

4.9.12 Install Logging Instructions

4.9.12.1 LogSet

LogSet on|off

Sets whether install logging to $INSTDIR\install.log will happen. $INSTDIR must have a value before you call this function or it will not work. Note that the NSIS_CONFIG_LOG build setting must be set (scons NSIS_CONFIG_LOG=yes) when building (it is not set by default) to support this. See Building NSIS for more information about recompiling NSIS.

设置是否安装日志到$INSTDIR\install.log

4.9.12.2 LogText

LogText text

If installer logging is enabled, inserts text "text" into the log file.

如果安装程序启用了日志记录,在日志文件中插入文本“text”。

IfFileExists $WINDIR\notepad.exe 0 +2
  LogText "$$WINDIR\notepad.exe exists"

4.9.13 Section Management

4.9.13.1 SectionSetFlags

SectionSetFlags section_index section_flags

Sets the section's flags. The flag is a 32-bit integer. The first bit (lowest) represents whether the section is currently selected, the second bit represents whether the section is a section group (don't modify this unless you really know what you are doing), the third bit represents whether the section is a section group end (again, don't modify), the fourth bit represents whether the section is shown in bold or not, the fifth bit represents whether the section is read-only, the sixth bit represents whether the section group is to be automatically expanded, the seventh bit is set for section groups which are partially selected, the eighth bit is internally used for partially selected section group toggling and the ninth bit is used for reflecting section name changes. The error flag will be set if an out of range section is specified.

设置条款的标志。

Each flag has a name, prefixed with SF_:

每个标志都有一个名称,前缀为“SF_”。

!define SF_SELECTED   1
!define SF_SECGRP     2
!define SF_SECGRPEND  4
!define SF_BOLD       8
!define SF_RO         16
!define SF_EXPAND     32
!define SF_PSELECTED  64

For an example of usage please see the one-section.nsi example.

For more useful macros and definitions, see Include\Sections.nsh.

Section test test_section_id
SectionEnd

Function .onInit
  # set section 'test' as selected and read-only
  IntOp $0 ${SF_SELECTED} | ${SF_RO}
  SectionSetFlags ${test_section_id} $0
FunctionEnd

4.9.13.2 SectionGetFlags

SectionGetFlags section_index user_var(output)

Retrieves the section's flags. See SectionSetFlags for a description of the flags. The error flag will be set if an out of range section is specified.

检索条款的标志。

Section test test_section_id
SectionEnd

Function .onSelChange
  # keep section 'test' selected
  SectionGetFlags ${test_section_id} $0
  IntOp $0 $0 | ${SF_SELECTED}
  SectionSetFlags ${test_section_id} $0
FunctionEnd

4.9.13.3 SectionSetText

SectionSetText section_index section_text

Sets the description for the section section_index. If the text is set to "" then the section will be hidden. The error flag will be set if an out of range section is specified.

设置条款section_index的描述。

Section "" test_section_id
SectionEnd

Function .onInit
  # change section's name to $WINDIR
  SectionSetText ${test_section_id} $WINDIR
FunctionEnd

4.9.13.4 SectionGetText

SectionGetText section_index user_var(output)

Stores the text description of the section section_index into the output. If the section is hidden, stores an empty string. The error flag will be set if an out of range section is specified.

将条款section_index的文本描述存储到输出中。

Section test test_section_id
SectionEnd

Function .onInit
  # append $WINDIR to section's name
  SectionGetText ${test_section_id} $0
  StrCpy $0 "$0 - $WINDIR"
  SectionSetText ${test_section_id} $0
FunctionEnd

4.9.13.5 SectionSetInstTypes

SectionSetInstTypes section_index inst_types

Sets the install types the section specified by section_index defaults to the enabled state in. Note that the section index starts with zero. Every bit of inst_types is a flag that tells if the section is in that install type or not. For example, if you have 3 install types and you want the first section to be included in install types 1 and 3, then the command should look like this:

设置由section_index指定的部分的安装类型默认为启用状态。

SectionSetInstTypes 0 5
because the binary value for 5 is "...00101". The error flag will be set if the section index specified is out of range.

Section test test_section_id
SectionEnd

Function .onInit
  # associate section 'test' with installation types 3 and 4
  SectionSetInstTypes ${test_section_id} 12
FunctionEnd

4.9.13.6 SectionGetInstTypes

SectionGetInstTypes section_index user_var(output)

Retrieves the install types flags array of a section. See above explanation about SectionSetInstTypes for a description of how to deal with the output. The error flag will be set if the section index is out of range.

获取条款的安装类型标志数组。

Section test test_section_id
SectionEnd

Function .onInit
  # associate section 'test' with installation types 5, on top of its existing associations
  SectionGetInstTypes ${test_section_id} $0
  IntOp $0 $0 | 16
  SectionSetInstTypes ${test_section_id} $0
FunctionEnd

4.9.13.7 SectionSetSize

SectionSetSize section_index new_size

Sets the size of the section specified by section_index. Note that the index starts with zero. The Value for Size must be entered in KiloByte and supports only whole numbers.

设置由section_index指定的条款的大小。

Section test test_section_id
SectionEnd

Function .onInit
  # set required size of section 'test' to 100 bytes
  SectionSetSize ${test_section_id} 100
FunctionEnd

4.9.13.8 SectionGetSize

SectionGetSize section_index user_var

Gets the size of the section specified by section_index and stores the value in the given user variable. Note that the index starts with zero. The error flag will be set if the section index is out of range.

获取section_index指定的条款的大小,并将值存储在给定的用户变量中。

Section test test_section_id
SectionEnd

Function .onInit
  # increase required size of section 'test' by 100 KiB
  SectionGetSize ${test_section_id} $0
  IntOp $0 $0 + 100
  SectionSetSize ${test_section_id} $0
FunctionEnd

4.9.13.9 SetCurInstType

SetCurInstType inst_type_idx

Sets the current InstType. inst_type_idx should be between 0 and 31. The error flag is not set if an out of range InstType was used.

设置当前的InstType

4.9.13.10 GetCurInstType

GetCurInstType user_var

Get the current InstType and stores it in user_var. If the first install type is selected, 0 will be put in user_var. If the second install type is selected, 1 will be put in user_var, and so on. The value of ${NSIS_MAX_INST_TYPES} (32 by default) means that the user selected a custom set of sections (Simply selecting "Custom" in the drop-down menu is not enough to trigger this, the value is calculated by the sections actually selected).

获取当前的InstType并将其存储在user_var中。

4.9.13.11 InstTypeSetText

InstTypeSetText inst_type_idx text

Sets the text of the specified InstType. If the text is empty then the InstType is removed. By using a previously unused inst_type_idx number you can create new InstTypes. To add/remove Sections to this new InstType see SectionSetInstTypes. Unlike SectionIn the index is zero based, which means the first install type's index is 0.

设置指定InstTypetext

InstType a
InstType b

Function .onInit
  # set first installation type's name to $WINDIR
  InstTypeSetText 0 $WINDIR
  # set second installation type's name to $TEMP
  InstTypeSetText 1 $TEMP
FunctionEnd

4.9.13.12 InstTypeGetText

InstTypeGetText inst_type_idx user_var

Gets the text of the specified InstType.

获取指定InstTypetext

InstType a
InstType b

Function .onInit
  InstTypeGetText 0 $0
  DetailPrint $0 # prints 'a'
  InstTypeGetText 1 $0
  DetailPrint $0 # prints 'b'
FunctionEnd

4.9.14 User Interface Instructions

4.9.14.1 BringToFront

Makes the installer window visible and brings it to the top of the window list. If an application was executed that shows itself in front of the installer, BringToFront would bring the installer back in focus.

使安装程序窗口可见,并将其置于窗口列表的顶部。

Recent Windows versions restrict the setting of foreground windows. If the user is working with another application during installation, the user may be notified using a different method.

4.9.14.2 CreateFont

CreateFont user_var(handle output) face_name [height] [weight] [/ITALIC] [/UNDERLINE] [/STRIKE]

Creates a font and puts its handle into user_var. For more information about the different parameters have a look at MSDN's page about the Win32 API function CreateFont().

创建一个字体并将其句柄放到user_var中。

You can get the current font used by NSIS using the ^Font and ^FontSize LangStrings.

!include WinMessages.nsh
GetDlgItem $0 $HWNDPARENT 1
CreateFont $1 "Times New Roman" "7" "700" /UNDERLINE
SendMessage $0 ${WM_SETFONT} $1 1

4.9.14.3 DetailPrint

DetailPrint user_message

Adds the string "user_message" to the details view of the installer.

将字符串“user_message”添加到安装程序的详细信息视图中。

DetailPrint "this message will be shown in the installation window"

4.9.14.4 EnableWindow

EnableWindow hwnd state(1|0)

Enables or disables mouse and keyboard input to the specified window or control. Possible states are 0 (disabled) or 1 (enabled).

启用或禁用指定窗口或控件的鼠标和键盘输入。

GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 0
Sleep 1000
EnableWindow $0 1

4.9.14.5 FindWindow

FindWindow user_var(hwnd output) windowclass [windowtitle] [windowparent] [childafter]

Searches for a window. Behaves like Win32's FindWindowEx(). Searches by windowclass (and/or windowtitle if specified). If windowparent or childafter are specified, the search will be restricted as such. If windowclass or windowtitle is specified as "", they will not be used for the search. If the window is not found the user variable is set to 0.

搜索窗口。

FindWindow $1 "#32770" "" $HWNDPARENT # Finds the inner dialog
FindWindow $2 "EDIT" "" $1 # Finds the first edit control in the inner dialog

4.9.14.6 GetDlgItem

GetDlgItem user_var(output) dialog item_id

Retrieves the handle of a control identified by item_id in the specified dialog box dialog. If you want to get the handle of a control in the inner dialog, first use FindWindow to get the handle of the inner dialog.

检索指定对话框对话框中由item_id标识的控件的句柄。

GetDlgItem $0 $HWNDPARENT 1 # next/install button

4.9.14.7 HideWindow

Hides the installer window.

隐藏安装程序窗口。

4.9.14.8 IsWindow

IsWindow HWND jump_if_window [jump_if_not_window]

If HWND is a window, Gotos jump_if_window, otherwise, Gotos jump_if_not_window (if specified).

如果HWND是一个窗口,则跳转jump_if_window,否则,跳转jump_if_not_window(如果指定)。

GetDlgItem $0 $HWNDPARENT 1
IsWindow $0 0 +3
  MessageBox MB_OK "found a window"
  Goto +2
  MessageBox MB_OK "no window"

4.9.14.9 LoadAndSetImage

LoadAndSetImage [/EXERESOURCE] [/STRINGID] [/RESIZETOFIT[WIDTH|HEIGHT]] ctrl imagetype lrflags imageid [user_var(imagehandle)]

Loads and sets a image on a static control. ctrl is the handle of the control. imagetype must 0 for bitmaps and 1 for icons (and the control style must match the image type). lrflags should be 0x10 to load from a file or 0 to load from a resource. imageid specifies the file path or resource name. Use /EXERESOURCE to load a resource from the installer .EXE. Use /STRINGID if imageid is a string, otherwise it is interpreted as a number. Use /RESIZETOFIT[WIDTH|HEIGHT] to resize the image to the dimensions of the control. imagehandle can optionally recieve the handle of the loaded image.

加载和设置静态控件上的图像。

Images loaded on individual pages should be destroyed to minimize resource leaks. If images are loaded into the same control multiple times, the previous image will only be destroyed if it is a bitmap image. Previous icons and 32-bit ARGB bitmaps must be retrieved with STM_GETIMAGE and destroyed.

应该销毁加载在各个页面上的图像,以最大限度地减少资源泄漏。如果图像被多次加载到同一个控件中,前一个图像只有在它是位图图像时才会被销毁。以前的图标和32位ARGB位图必须用STM_GETIMAGE检索并销毁。

LoadAndSetImage /EXERESOURCE $hIconStatic 1 0 103
LoadAndSetImage /STRINGID /RESIZETOFITWIDTH $hBmpStatic 0 0x10 "$PluginsDir\myimg.bmp"

4.9.14.10 LockWindow

LockWindow on|off

LockWindow on prevents the main window from redrawing itself upon changes. When LockWindow off is used, all controls that weren't redrawn since LockWindow on will be redrawn. This makes the pages flickering look nicer because now it flickers a group of controls at the same time, instead of one control at a time. The individual control flickering is more noticeable on old computers.

LockWindow阻止主窗口在更改时重绘自己。

4.9.14.11 SendMessage

SendMessage HWND msg wparam lparam [user_var(return value)] [/TIMEOUT=time_in_ms]

Sends a message to HWND. If a user variable $x is specified as the last parameter (or one before the last if you use /TIMEOUT), the return value from SendMessage will be stored in it. Note that when specifying 'msg' you must just use the integer value of the message. Include WinMessages.nsh to have all Windows messages defined in your script. If you wish to send strings use "STR:a string" as wParam or lParam where needed. Use /TIMEOUT=time_in_ms to specify the duration, in milliseconds, of the time-out period.

发送消息到“HWND”。

!include WinMessages.nsh
FindWindow $0 "Winamp v1.x"
SendMessage $0 ${WM_CLOSE} 0 0

GetDlgItem $1 $HWNDPARENT 2
SendMessage $1 ${WM_SETTEXT} 0 "STR:Goodbye"

4.9.14.12 SetAutoClose

SetAutoClose true|false

Overrides the default auto window-closing flag (specified for the installer using AutoCloseWindow, and false for the uninstaller). Specify 'true' to have the install window immediately disappear after the install has completed, or 'false' to make it require a manual close.

覆盖默认的自动窗口关闭标志。

4.9.14.13 SetBrandingImage

SetBrandingImage [/IMGID=item_id_in_dialog] [/RESIZETOFIT] path_to_bitmap_file.bmp

Sets the current bitmap file displayed as the branding image. If no IMGID is specified, the first image control found will be used, or the image control created by AddBrandingImage. Note that this bitmap must be present on the user's machine. Use File first to put it there. If /RESIZETOFIT is specified the image will be automatically resized (very poorly) to the image control size. If you used AddBrandingImage you can get this size by compiling your script and watching for AddBrandingImage output, it will tell you the size. SetBrandingImage will not work when called from .onInit!

设置显示为品牌图像的当前位图文件。

4.9.14.14 SetDetailsView

SetDetailsView show|hide

Shows or hides the details on the InstFiles page, depending on which parameter you pass. Overrides the default details view, which is set via ShowInstDetails.

显示或隐藏InstFiles页面上的详细信息,取决于您传递的参数。

4.9.14.15 SetDetailsPrint

SetDetailsPrint none|listonly|textonly|both|lastused

Sets mode at which commands print their status. None has commands be quiet, listonly has status text only added to the listbox, textonly has status text only printed to the status bar, and both enables both (the default). For extracting many small files, textonly is recommended (especially on Win9x with smooth scrolling enabled).

设置命令打印其状态的模式。

SetDetailsPrint none
File "secret file.dat"
SetDetailsPrint both

4.9.14.16 SetCtlColors

SetCtlColors hwnd [/BRANDING] [text_color|SYSCLR:text_color_id] [transparent|bg_color|SYSCLR:bg_color_id]

Sets the text and background color of a static control, edit control, button or a dialog. text_color and bg_color don't accept variables. Use GetDlgItem to get the handle (HWND) of the control. To make the control transparent specify transparent as the background color value. Prefix the color value with SYSCLR: to specify a Windows COLOR_* constant. You can also specify /BRANDING with or without text color and background color to make the control completely gray (or any other color you choose). This is used by the branding text control in the MUI.

设置静态控件、编辑控件、按钮或对话框的文本和背景颜色。

Page Components "" CmpntPageShow
Function CmpntPageShow
FindWindow $1 "#32770" "" $HWNDPARENT
GetDlgItem $0 $1 1006
SetCtlColors $0 0xFF0000 0x00FF00 ; Red on Green
GetDlgItem $0 $1 1022
SetCtlColors $0 SYSCLR:23 SYSCLR:24 ; COLOR_INFOTEXT on COLOR_INFOBK
FunctionEnd

Warning: Setting the background color of check boxes to transparent may not function properly when using XPStyle on. The background may be completely black instead of transparent when using certain Windows themes. The text color might also be ignored when Visual Styles are enabled.

4.9.14.17 SetSilent

SetSilent silent | normal

Sets the installer to silent mode or normal mode. See SilentInstall for more information about silent installations. Can only be used in .onInit.

将安装程序设置为“静默”模式或“正常”模式。

4.9.14.18 ShowWindow

ShowWindow hwnd show_state

Sets the visibility of a window. Possible show_states are the same as the Windows ShowWindow function. SW_* constants are defined in Include\WinMessages.nsh.

设置窗口的可见性。

!include WinMessages.nsh
GetDlgItem $0 $HWNDPARENT 1
ShowWindow $0 ${SW_HIDE}
Sleep 1000
ShowWindow $0 ${SW_SHOW}

4.9.15 Multiple Languages Instructions

4.9.15.1 LoadLanguageFile

LoadLanguageFile language_file.nlf

Loads a language file for the construction of a language table. All of the language files that ship with NSIS are in Contrib\Language Files

加载用于构造语言表的语言文件。

After you have inserted the language file ${LANG_langfile} will be defined as the language id (for example, ${LANG_ENGLISH} will be defined as 1033). Use it with LangString, LicenseLangString, LangDLL and VIAddVersionKey.

4.9.15.2 LangString

LangString name language_id|0 string

Defines a multilingual string. This means its value may be different (or not, it's up to you) for every language. It allows you to easily make your installer multilingual without the need to add massive switches to the script.

定义一个多语言字符串。

Each language string has a name that identifies it and a value for each language used by the installer. They can be used in any runtime string in the script. To use a language string all you need to add to the string is $(LangString_name_here) where you want the LangString to be inserted.

Notes:

  • Unlike defines that use curly braces - {}, language strings use parenthesis - ().
  • If you change the language in the .onInit function, note that language strings in .onInit will still use the detected language based on the user's default Windows language because the language is initialized after .onInit.
  • Always set language strings for every language in your script.
  • If you set the language ID to 0 the last used language by LangString or LoadLanguageFile will be used.

Example of usage:

LangString message ${LANG_ENGLISH} "English message"
LangString message ${LANG_FRENCH} "French message"
LangString message ${LANG_KOREAN} "Korean message"

MessageBox MB_OK "A translated message: $(message)"

4.9.15.3 LicenseLangString

LicenseLangString name language_id|0 license_path

Does the same as LangString only it loads the string from a text/RTF file and defines a special LangString that can only be used by LicenseData.

做相同的LangString,只是它从text/RTF文件加载字符串,并定义一个特殊的LangString,只能被LicenseData使用。

LicenseLangString license ${LANG_ENGLISH} license-english.txt
LicenseLangString license ${LANG_FRENCH} license-french.txt
LicenseLangString license ${LANG_GERMAN} license-german.txt

LicenseData $(license)