NSIS 安装包默认支持的参数

NSIS 安装包默认支持的参数

NSIS 制作的安装包默认支持 /NCRC、/S、/D= 三个参数,详见下文 3.2 Installer Usage(来自 Command Line Usage)。

以上三个参数对应的功能分别为禁止 CRC 校验、静默安装、设置安装路径,这三个功能不需要自己在 NSI 脚本里开发就默认支持。

3.2 Installer Usage

Generated installers and uninstallers accept a few options on the command line. These options give the user a bit more control over the installation process.

3.2.1 Common Options

  • /NCRC disables the CRC check, unless CRCCheck force was used in the script.
  • /S runs the installer or uninstaller silently. See section 4.12 for more information.
  • /D sets the default installation directory ($INSTDIR), overriding InstallDir and InstallDirRegKey. It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces. Only absolute paths are supported.

3.2.2 Uninstaller Specific Options

  • _?= sets $INSTDIR. It also stops the uninstaller from copying itself to the temporary directory and running from there. It can be used along with ExecWait to wait for the uninstaller to finish. It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces.

3.2.3 Examples

installer.exe /NCRC
installer.exe /S
installer.exe /D=C:\Program Files\NSIS
installer.exe /NCRC /S /D=C:\Program Files\NSIS
uninstaller.exe /S _?=C:\Program Files\NSIS
# uninstall old version
ExecWait '"$INSTDIR\uninstaller.exe" /S _?=$INSTDIR'

关于静默安装参数 /S

只要指定了 /S 参数(S 必须大写),NSIS 脚本中 IfSilent 函数就会自动返回 true,这是 NSIS 内置支持的,不需要自己在 NSIS 脚本中写代码来解析。

来自官方文档中 IfSilent 的函数说明:

(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.)

关于选盘参数 /D=

XXXSetup.exe /D=C:\Program Files (x86)

如上,给安装包指定这个参数后,会自动赋值给 $INSTDIR 变量。并且如果在安装包内调用 ${GetParameters} $R0 来获取安装包参数时,将获取不到 /D= 参数,被 NSIS 自己吃掉了,不会传给 NSI 脚本

如果想自己处理 /D= 参数,比如加一些自己的逻辑,必须换个参数,比如改为 /d=(即 D 改为小写的 d)。

另外,注意:

1. 这个参数指定的路径不能包含引号,即使路径中含有空格。

2. 该参数支持创建多级文件夹。

上面说的 /D= 参数被 NSIS 自己吃掉的问题,参考帖子:

windows - NSIS weird behavior with GetParameters - Stack Overflow

相关推荐

  1. NSIS 安装windows 安装(包括QT和MFC)

    2024-06-06 00:40:03       29 阅读
  2. C++:默认参数竟是静态

    2024-06-06 00:40:03       25 阅读
  3. 第二十七章 配置 Web Gateway 默认参数 - 安全

    2024-06-06 00:40:03       19 阅读
  4. C++中函数默认参数(缺省参数

    2024-06-06 00:40:03       36 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-06 00:40:03       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-06 00:40:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-06 00:40:03       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-06 00:40:03       20 阅读

热门阅读

  1. Fortran入门(一)(期末复习)

    2024-06-06 00:40:03       8 阅读
  2. Springboot整合kafka简单使用

    2024-06-06 00:40:03       9 阅读
  3. chrome 浏览器历史版本下载

    2024-06-06 00:40:03       8 阅读
  4. solus linux 简介

    2024-06-06 00:40:03       7 阅读
  5. 【第5章】SpringBoot实战篇之登录模式切换

    2024-06-06 00:40:03       10 阅读
  6. 游戏心理学Day02

    2024-06-06 00:40:03       10 阅读
  7. 枚举,typedef,位运算

    2024-06-06 00:40:03       8 阅读
  8. 如何在JVM中基于引用计数法实现GC

    2024-06-06 00:40:03       7 阅读
  9. 代码随想录leetcode200题之动态规划算法

    2024-06-06 00:40:03       7 阅读