如何使用NSIS进行自我提取?

时间:2016-03-01 19:20:56

标签: nsis

我想创建一个自解压exe(abcdInstaller.exe),它运行另一个exe(AppInstaller.apk,这是在我的电脑上安装abcd.apk)。下面的脚本工作正常,但是当我运行abcdInstaller.exe时,它还会在当前目录中提取这两个文件(从我运行此exe的位置)并运行AppInstaller.exe。

但是我想要的是,用户只需单击abcdInstaller.exe,abcdInstaller.exe将在后台运行AppInstaller.exe,这将完成其工作。

!include LogicLib.nsh
!include WinMessages.nsh


SilentInstall silent
RequestExecutionLevel user ;no elevation needed for this test
ShowInstDetails hide

# this will be the created executable archive
OutFile "abcdInstaller.exe"

InstallDir $EXEDIR

# the executable part
Section

# define the output path for the following files
SetOutPath $INSTDIR

# define what to install and place it in the output path...
# ...app...
File AppInstaller.exe
# ...and the library.
File abcd.apk

# run application
ExecShell "open" "AppInstaller.exe"

# done
SectionEnd

我尝试评论SetOutPath $ INSTDIR,但后来没有任何反应。

请提出一些建议。

2 个答案:

答案 0 :(得分:0)

我正在更新我的解决方案。

我正在将exe复制到临时文件夹,并在完成该过程后删除该文件夹。

!include LogicLib.nsh
!include WinMessages.nsh


SilentInstall silent
RequestExecutionLevel user ;no elevation needed for this test
ShowInstDetails hide

# this will be the created executable archive
OutFile "ABCD.exe"

InstallDir $EXEDIR


# the executable part
Section

# define the output path for the following files
SetOutPath $TEMP\ApkPath

# define what to install and place it in the output path...
# ...your app...
File AppInstaller.exe
# ...and the library.
File xyz.apk

# run your application
ExecWait "$TEMP\ApkPath\AppInstaller.exe"

SetOutPath $TEMP

RMDir /r $TEMP\ApkPath

# done
SectionEnd

答案 1 :(得分:0)

您应该将$ PluginsDir用于安装期间临时使用的文件:

SilentInstall silent
RequestExecutionLevel user
OutFile "Test.exe"

Section
InitPluginsDir
SetOutPath $PluginsDir
File "MyApp.exe"
ExecWait '"$PluginsDir\MyApp.exe"' ; Double quotes on the path

SetOutPath $Temp ; SetOutPath locks the directory and we don't want to lock $PluginsDir
SectionEnd