【问题标题】:Trying to add command-line argument execution to NSIS installer尝试将命令行参数执行添加到 NSIS 安装程序
【发布时间】:2012-06-25 16:18:37
【问题描述】:

我正在尝试自定义 NSIS 安装程序。根据用户的选项,我希望程序使用不同的选项运行,我将使用命令行选项进行设置。

(我保存了一些我在最后删除的文件,如果用户不想继续安装,那么我想使用仅删除临时文件的选项 -d 运行该实用程序。)

我找到了这篇文章:Accessing command line arguments in NSIS,但我不知道如何设置它来运行带有命令行参数的程序。

这就是我正在尝试的: 我试过了:

SetOutPath "$TEMP"
!define MY_FILE "file.exe -d"
File /nonfatal "${MY_FILE}"
ExecWait '"$TEMP\${MY_FILE}" 
Delete /REBOOTOK "$TEMP\${MY_FILE}"

我收到一条警告说它没有找到 file.exe -d

所以我正在尝试类似的东西

$(GetOptions) $CMDLINE "/d" $Trying_This
;Not sure what to put to get the program

我还在尝试 NSIS,这是一个巨大的挑战,找不到可以指导我的示例。

注意:我正在运行没有选项的文件,然后我希望 NSIS 插入选项 -d(或其他选项,如 -f 文件名)

编辑:我在帖子中有不完整的代码...我在现实生活中有 ExecWait...

【问题讨论】:

    标签: installation command-line-arguments nsis


    【解决方案1】:
    Outfile test.exe
    requestexecutionlevel user
    InstallDir "$Temp\Test" ;Default $InstDir
    !include FileFunc.nsh
    !include LogicLib.nsh
    
    page directory
    page instfiles
    
    section 
    StrCpy $1 "/Foo"
    ClearErrors
    ${GetOptions} $CMDLINE "-d" $0
    ${IfNot} ${Errors} 
        StrCpy $1 "/Bar"
    ${EndIF}
    SetOutPath $InstDir
    File "File.exe" ;Extracting to $InstDir
    ExecWait '"$InstDir\File.exe" $1' ;Calling with /Foo or if installer was started with -d; /Bar 
    sectionend
    

    【讨论】:

    • 如果 file.exe 仅在安装过程中使用,您可能不应该将其解压缩到 $instdir,您应该调用 Initpluginsdir 然后将其解压缩到 $pluginsdir
    【解决方案2】:

    File 语句使 NSIS 将给定文件包含到压缩数据中,并在运行时将其放入当前工作目录(您可以使用SetOutPath 更改)。它不会让您执行带有或不带参数的可执行文件。

    如果您想在安装期间运行可执行文件,您必须 1) 包含 exe 并 2) 在运行时执行它,并可能更改为临时目录,例如如果可执行文件是安装程序。

    !define MY_FILE "file.exe"
    !define MY_ARGS "-d"
    SetOutPath "$TEMP" 
    File "${MY_FILE}"
    ExecWait '$TEMP\${MY_FILE} ${MY_ARGS}' $0   ;$0 will get the return code
    ${if} $0 <> 0
        MessageBox MB_OK|MB_ICONEXCLAMATION "Sorry, but the installation returned the code $0.$\n \
             Cannot continue the installation." /SD IDOK
        Abort
    ${endif}
    Delete "$TEMP\${MY_FILE}"
    

    当然如果你需要保留exe之后不要去临时目录也不要删除最后的可执行文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多