Archive: run bat file in WindowXP


run bat file in WindowXP
Hi, all, I'm a fresher, I want to run a bat in my setup, but I tried several routines and none succeeded. Any expert can help me?

Refer to the -RunScript section. Every exec command just shows the command line black window but no bat excuted, why?

Here is my bat:

rem Test
echo this is exec: %1
notepad
pause
rem Test End

Here is my nsi file:

!Define PRODUCT_NAME "My application"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "My company, Inc."
!define PRODUCT_WEB_SITE "http://www.mycompany.com"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup.exe"
InstallDir "C:\My application"
ShowInstDetails show
ShowUnInstDetails show

Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite try
File "D:\AENet\NSISWorkSpace\testExec\src\exec.bat"
WriteUninstaller "$INSTDIR\uninst.exe"
SectionEnd

Section -RunScript
;ReadEnvStr $0 COMSPEC
ExpandEnvStrings $0 %COMSPEC%
Exec '"$0" "$INSTDIR\exec.bat"'
MessageBox MB_OK "exec"
Exec 'cmd.exe "$INSTDIR\exec.bat"'
MessageBox MB_OK "execwait"
ExecWait '$0 "$INSTDIR\exec.bat"'
MessageBox MB_OK "execshell"
ExecShell "" "$INSTDIR\exec.bat" $InstDir SW_ShowNormal
MessageBox MB_OK "nsisexec"
nsExec::Exec '$0 "$INSTDIR\exec.bat" "$INSTDIR"'
SectionEnd


Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd

Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
Abort
FunctionEnd

Section Uninstall
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\exec.bat"
RMDir "$INSTDIR"

SetAutoClose true
SectionEnd


no need to post your full script (and if, please attach it). you need to use ExecShell for bat files, Exec is for executables only.

http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.1.3


Thanks for you reply, I also tried ExecShell, but I found I can NOT add correct parameters to this running, like I want to execute:
exec.bat "c:\my project"
but in execshell, always is:
exec.bat c:\my
params after the space are lost.


See my tries, all these are wrong:

Section -RunScript
;ReadEnvStr $0 COMSPEC
ExpandEnvStrings $0 %COMSPEC%
Exec '"$0" "$INSTDIR\exec.bat"'
MessageBox MB_OK "exec"
Exec 'cmd.exe "$INSTDIR\exec.bat"'
MessageBox MB_OK "execwait"
ExecWait '$0 "$INSTDIR\exec.bat"'
MessageBox MB_OK "execshell"
ExecShell "" "$INSTDIR\exec.bat" $InstDir SW_ShowNormal
MessageBox MB_OK "nsisexec"
nsExec::Exec '$0 "$INSTDIR\exec.bat" "$INSTDIR"'
SectionEnd


At last I found the resolution, I must add many quote to abide spaces, below three are right, but still has problem with execshell and nsExec:Exec

ExpandEnvStrings $0 %COMSPEC%
Exec '"$0" /C ""$INSTDIR\exec.bat" "$InstDir""'
MessageBox MB_OK "exec"
Exec 'cmd.exe /K ""$INSTDIR\exec.bat" "$InstDir""'
MessageBox MB_OK "execwait"
ExecWait '$0 /C ""$INSTDIR\exec.bat" "$InstDir""'


There are a lot of threads about this, you might try a search for it:

http://forums.winamp.com/showthread....hreadid=161259


Thanks!


It's pretty simple:

ReadEnvStr $R0 COMSPEC
nsExec::ExecToLog `"$R0" /C "$INSTDIR\exec.bat"`
Pop $R0

You can also use ExecDos::exec /DETAILED which I prefer:
http://nsis.sourceforge.net/ExecDos_plug-in

Stu