0

How we can schedule a task in windows scheduler using batch file. I want to set a scheduler using batch command.

echo off
title Install Pentaho
set /p downloadPentaho=Dowload Pentaho [y/n]?: 
if %downloadPentaho%==y (call :download_pentaho) else (echo termenating program)
set /p downloadKtr=Dowload KTR files [y/n]?: 
if %downloadKtr%==y (call :download_ktr) else (echo termenating program) 
REM extract the ktr files and schedule pentaho in the windows server
set /p downloadBatch=Dowload Pentaho [y/n]?: 
EXIT /B 0

:download_pentaho
SET downloadUrl=http://example.com/pentaho/pentaho.zip
echo dowloading
powershell -Command "Invoke-WebRequest %downloadUrl% -OutFile pentaho.zip"
mkdir "C:\Users\Nilanjan Bose\bika_test\Pentaho\design-tools"
call :UnZipFile "C:\Users\Nilanjan Bose\bika_test\Pentaho\design-tools" "C:\Users\Nilanjan Bose\bika_test\pentaho.zip"
EXIT /B 0

:download_ktr
SET downloadUrl=http://example.com/pentaho/ktr.zip
echo dowloading
powershell -Command "Invoke-WebRequest %downloadUrl% -OutFile ktr.zip"
mkdir "C:\schedular"
call :UnZipFile "C:\schedular" "C:\Users\Nilanjan Bose\bika_test\ktr.zip"
EXIT /B 0

:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs%  echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
marijnr
  • 344
  • 3
  • 6
  • 24
  • 1
    Welcome to Super User! What have you tried so far? What research have you done? :) – bertieb Jun 14 '18 at 10:54
  • I have created a batch file. Now using that batch file i want to schedule a task which runs another batch file. – Bhagyashree Sarkar Jun 14 '18 at 10:59
  • why does it need to be a batch file? – marijnr Jun 14 '18 at 11:01
  • Need to execute pentaho in windows server at certain time. – Bhagyashree Sarkar Jun 14 '18 at 11:03
  • Windows has a build-in task scheduler tool that you can configure to run a batch file at certain time instances. Would this work for your problem? – marijnr Jun 14 '18 at 11:06
  • If I understand, you want a subroutine to be added to your batch that allows you to also add a task to run pentaho after you download and install it. Is that it? – cdlvcdlv Jun 14 '18 at 11:06
  • @cdlvcdlv yes.. You are correct. – Bhagyashree Sarkar Jun 14 '18 at 11:07
  • Open task scheduler, create manually your task and export it as xml. You then add redirected `echo` s to your batch as you need (just as you do with `_.vbs`) and [do this](https://superuser.com/questions/575644/how-to-import-a-scheduled-task-automatically-from-an-xml-file). [Your batch will need admin rights](https://stackoverflow.com/questions/7044985/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-administrator), of course. – cdlvcdlv Jun 14 '18 at 11:15
  • Do we have any alternate way. I want do this with batch command only. No manual work :( – Bhagyashree Sarkar Jun 14 '18 at 11:28
  • *I want do this with batch command only.* What about using OS component/program (such as schtasks.exe or at.exe)? It's not a batch command, it's not what you want? – Akina Jun 14 '18 at 12:20
  • @bhagyashreesarkar This is batch command only. You must create manually the task only once, merge the generated xml data into your batch, and then the batch will recreate the task in every computer you run it. Please read carefully. – cdlvcdlv Jun 15 '18 at 08:12
  • @bhagyashreesarkar Here you got an [example](https://stackoverflow.com/a/26079505/6456701). And here the [Task Scheduler Schema](https://msdn.microsoft.com/en-us/library/windows/desktop/aa383609(v=vs.85).aspx). – cdlvcdlv Jun 15 '18 at 08:21

0 Answers0