mm1985
mm1985

Reputation: 231

Batch file - restart program after every 20 minutes

I want to create batch file which starts a program and after 20 minutes will close the program and start it again.

The only thing I know about a batch file is how to start a program:

@echo off
Start [adress of application]

Upvotes: 18

Views: 85214

Answers (4)

Ezekiel Udoh
Ezekiel Udoh

Reputation: 1

@echo off                           
:loop                               
timeout /t 20 >null   ( Wait for 20 seconds before kill program)            
taskkill /F /IM terminal.exe  
timeout /t 3600 >null ( wait for 1hr before returning to loop or recycle the process)           
goto loop              

I use another program called mt4bar to monitor my application and relaunch them anytime they crash or get closed

Upvotes: -1

Ian
Ian

Reputation: 3149

This works:

@echo off                           //Turn off screen text messages
:loop                               //Set marker called loop, to return to
start "Wicked_Article_Creator" "C:\Wicked Article Creator\Wicked Article Creator.exe"  //Start program, with title and program path 
timeout /t 1200 >null               //Wait 20 minutes
taskkill /f /im "Image Name" >nul   //Image name, e.g. WickedArticleCreator.exe, can be found via Task Manager > Processes Tab > Image Name column (look for your program)
timeout /t 7 >null                  //Wait 7 seconds to give your prgram time to close fully - (optional)
goto loop                           //Return to loop marker

Upvotes: 24

RAJ
RAJ

Reputation: 7

For anyone coming across this old question: Instead of timeout.exe you can also ping to an address that definitely doesn't exist:

ping 999.199.991.91 -n 1 -w 60000 >NUL

You can change 60000 to whatever delay you want (in ms).

1 second = 1000

10 seconds = 10000

60 seconds = 60000

And so on..

Upvotes: -1

Magoo
Magoo

Reputation: 80023

@echo off
:loop
start yourtarget.exe ...
timeout /t 1200 >null
taskkill /f /im yourtarget.exe >nul
goto loop

should do the job.

Upvotes: 7

Related Questions