1

我正在尝试自定义 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......

4

2 回答 2

2
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
于 2012-06-25T17:13:02.253 回答
1

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之后不要去临时目录,也不要在最后删除可执行文件。

于 2012-06-25T16:59:08.483 回答