Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 8th July 2009, 09:34   #1
DanielTao
Junior Member
 
Join Date: Jul 2009
Location: China
Posts: 5
Question 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
DanielTao is offline   Reply With Quote
Old 8th July 2009, 09:52   #2
Yathosho
Forum King
 
Yathosho's Avatar
 
Join Date: Jan 2002
Location: AT-DE
Posts: 3,167
Send a message via ICQ to Yathosho
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
Yathosho is online now   Reply With Quote
Old 9th July 2009, 01:08   #3
DanielTao
Junior Member
 
Join Date: Jul 2009
Location: China
Posts: 5
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.
DanielTao is offline   Reply With Quote
Old 9th July 2009, 01:11   #4
DanielTao
Junior Member
 
Join Date: Jul 2009
Location: China
Posts: 5
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
DanielTao is offline   Reply With Quote
Old 9th July 2009, 05:44   #5
DanielTao
Junior Member
 
Join Date: Jul 2009
Location: China
Posts: 5
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""'
DanielTao is offline   Reply With Quote
Old 9th July 2009, 05:59   #6
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 546
There are a lot of threads about this, you might try a search for it:

http://forums.winamp.com/showthread....hreadid=161259
jpderuiter is offline   Reply With Quote
Old 10th July 2009, 01:19   #7
DanielTao
Junior Member
 
Join Date: Jul 2009
Location: China
Posts: 5
Thanks!
DanielTao is offline   Reply With Quote
Old 10th July 2009, 11:02   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
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

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump