Skip to content
⌘ NSIS Forum Archive

Script to execute a bat

11 posts

Guest#

Script to execute a bat

I suck at scripting... but I need a script to execute a .bat file after extracting everything. Can anyone help me?
Takhir#
To hide DOS window use nsExec (nsis\contrib\nsexec) or ExecDos. Anders' remark in the ExecDos thread about bat files execution is important.
Guest#
Is there a way to make sure that the files get extracted in a precice folder? Because the paths in the .bat needs it.
Afrow UK#
Use SetOutPath first.
..or..
for single files you can use:
File "/oname=$INSTDIR\file.ext" "localfile.ext"

-Stu
Guest#
One last thing... how can I make this work?
ExecShell "at 00:00 /every:Su,M,T,W,Th,F,S "cd $INSTDIR | .\update.bat""
Comperio#
The ExecShell command is used to execute Windows shell commands, which appear in the "right-click" menu--things such as "open", "print", etc.

So, to run a batch file, it would be something like this:

ExecShell "open" "C:\path\update.bat"
But looking at your example, it seems that that you also want to run this as batch file as a scheduled task. The only way that I know of doing this is to incorporate this into Windows as a scheduled task. This means that you're going to have to make some type of API call or call to an external EXE that will set this up.

Take a look at this forum topic to get some more information about setting up scheduled tasks in Windows:
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
Afrow UK#
Well, 'at' is a command-line executable so you just need to call it with %COMSPEC%:

ReadEnvStr $R0 COMSPEC
nsExec::Exec '"$R0" /C at 00:00 /every:Su,M,T,W,Th,F,S "cd $INSTDIR | .\update.bat"'
Edit: However, I don't think at.exe is on Win9x therefore the Scheduled Tasks link will be bettr.

.bat files are not a registered Windows Shell file type as they are part of DOS/CMD. Therefore you do not need to use ExecShell on them - they act like an exe, hence why you can even use them for Shell on other file types.

-Stu