如何在安装后立即使用参数执行应用程序?

时间:2019-02-05 21:41:14

标签: nsis

我的安装EXE应该将其自身解压缩到一个temp文件夹中,然后在其中执行一个应用程序(带有传递的args),再次返回并删除该temp文件夹。 如何编写nsi脚本?

2 个答案:

答案 0 :(得分:1)

在我看来,您正在尝试创建便携式应用程序。当原始作者添加对便携式应用程序的支持时,便携式应用程序总是更好的,因为它可以正确处理注册表和其他配置文件。

如果您仍想创建启动器应用程序,则可以执行以下操作:

OutFile "MyLauncher.exe"
RequestExecutionLevel User
SilentInstall Silent
SetCompressor LZMA

!include FileFunc.nsh
!insertmacro GetParameters

Section
${GetParameters} $1
InitPluginsDir
SetOutPath $PluginsDir
File "c:\myfiles\MyApp.exe"
File /r "c:\myfiles\otherfiles\*.*" ; If you need to include other files required by the application
ExecWait '"$PluginsDir\MyApp.exe" /param1 "pa ra m2" /param3 $1' $0 ; $1 contains the parameters passed to your launcher, remove it if you don't want to pass those arguments
SetErrorLevel $0
SetOutPath $Temp ; Don't lock $PluginsDir so it can be deleted automatically by the installer
SectionEnd

答案 1 :(得分:0)

回答我自己的问题。 所需的nsi脚本框架应如下所示:

# The name of the installer (arbitrary)
Name "hello"

# The name of the installation file
OutFile "hello.exe"

# where put the installation - other options would be $TEMP, etc.
InstallDir $DESKTOP

RequestExecutionLevel user         # no Windows UAC popup please!
SilentInstall silent               # completely silent install
SetCompressor /SOLID /FINAL lzma   # max compression for inst. file

# The stuff to install
Section ""
  SetOutPath $INSTDIR              # where to install (overwritable by user!)
  File /r D:\...\...               # where the install material lives
SectionEnd

# this function auto-runs after installation is fine
Function .onInstSuccess
  # parameter are passed through via $CMDLINE
  ExecWait '"$OUTDIR\hello.dist\hello.exe" $CMDLINE'
  RMDir /r "$OUTDIR\hello.dist"    # remove install folder again
FunctionEnd