1

I have builded nsis script successfully for my java project.I have a batch file that I need to run within my NSIS installer.It must run after all the files have been extracted.I have tried following commands

!define MUI_FINISHPAGE_RUN $INSTDIR\bin\batch.bat

This one also have tried:

SetOutPath $INSTDIR
ExpandEnvStrings $0 %COMSPEC%
nsExec::ExecToStack '"$INSTDIR\batch.bat"'

I have referred this link.

My Requirement is:

1.How to start batch file after installation completion using Nsis script?

Community
  • 1
  • 1
Ami
  • 4,241
  • 6
  • 41
  • 75

1 Answers1

1

Why call ExpandEnvStrings if you are not going to use the result? The path does not even match in your two examples.

As long as you get the path and quotes correct it should work:

!include MUI2.nsh
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION RunBatch
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English

Function RunBatch
;The most basic version, runs with visible console:
ExecWait '"$temp\test.cmd" /foo "bar baz" /blergh'

;You must use cmd.exe if you want redirection (With stupid extra quotes for cmd.exe):
ExpandEnvStrings $0 %COMSPEC%
ExecWait '"$0" /C ""$temp\test.cmd" /foo "bar baz" /blergh > "$temp\stdout.txt""'

;Use one of the exec plugins if you want to hide the console:
nsExec::Exec '"$temp\test.cmd" /foo "bar baz" /blergh'
FunctionEnd

There are several exec plugins you can use depending on your needs: nsExec, ExecDos or ExecCmd

Anders
  • 97,548
  • 12
  • 110
  • 164