Как запустить приложение сразу после установки ... с аргументами? - PullRequest
0 голосов
/ 06 февраля 2019

Мой установочный EXE должен разархивировать себя во временную папку, затем запустить в ней приложение (с передачей аргументов), вернуть и снова удалить временную папку.Как мне написать скрипт nsi?

Ответы [ 2 ]

0 голосов
/ 06 февраля 2019

Отвечая на мой собственный вопрос.Необходимый скелет 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
0 голосов
/ 06 февраля 2019

Мне кажется, что вы пытаетесь создать портативное приложение.Портативные приложения всегда лучше, когда оригинальный автор добавляет поддержку для них, потому что они могут правильно обрабатывать реестр и другие файлы конфигурации.

Если вы все еще хотите создать приложение запуска, вы можете сделать что-то вроде этого:

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