1

I am having issues in running a batch file with certain parameters in NSIS installer.

I have followed the instructions mentioned in Executing Batch File in NSIS installer

The command i am using is

SetOutPath "$INSTDIR\64-bitRegistration"

ExpandEnvStrings $0 %COMSPEC%

ExecWait '"$0" "$INSTDIR\64-bitRegistration\EIQServersRegistration.cmd" "$INSTDIR\Param1" "$INSTDIR\Param2" "$INSTDIR\Param3" "$INSTDIR\Param4" "$INSTDIR\Param5"'

I using .cmd instead of .bat. I have quoted the parameters for ExecWait.

What I am facing is it opens the command prompts and do nothing. The command prompt is not taking the batch file and it does not execute the batch file.

Can someone point out what is that I am missing.

Community
  • 1
  • 1

1 Answers1

1

When using %COMSPEC% you have to prepend /C to the parameters to tell cmd.exe that you want to execute the rest of the command line. This only half the story because cmd.exe has silly quote handling that you have to disable with the if 1==1 hack:

Section
; Create test batch file:
InitPluginsDir
StrCpy $InstDir $PluginsDir
CreateDirectory "$INSTDIR\64-bitRegistration"
FileOpen $0 "$INSTDIR\64-bitRegistration\EIQServersRegistration.cmd" w
FileWrite $0 '@echo off$\n'
FileWrite $0 'Title Test batch %*$\n'
FileWrite $0 'dir /S/B %windir%\*shell32*$\n' ; Some long running command
FileClose $0

; Run it:
ExpandEnvStrings $0 %COMSPEC% 
ExecWait '"$0" /C if 1==1 "$INSTDIR\64-bitRegistration\EIQServersRegistration.cmd" "foo" bar "b a z"'

; Or let Windows select the batch handler:
ExecWait '"$INSTDIR\64-bitRegistration\EIQServersRegistration.cmd" "foo" bar "b a z"'
SectionEnd
Anders
  • 97,548
  • 12
  • 110
  • 164