Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file - restart program after every 20 minutes

Tags:

batch-file

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]
like image 890
mm1985 Avatar asked Mar 24 '13 19:03

mm1985


People also ask

How to restart program with Batch File?

Step 1: Make the Batch File Click the right mouse button, hover over "New", and click "Text Document". Give it the name you want the command to be called (restart), followed by . bat (restart.

How do I make programs restart automatically?

Press Win+I to open Windows Settings. Go to Accounts > Sign-in options. Find the Automatically save my restartable apps and restart them when I sign back in setting. Toggle the respective button to turn it on.

What does %1 do in batch?

When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.

How do I put a timed pause in a batch file?

You can insert the pause command before a section of the batch file that you might not want to process. When pause suspends processing of the batch program, you can press CTRL+C and then press Y to stop the batch program.


2 Answers

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

should do the job.

like image 24
Magoo Avatar answered Sep 20 '22 16:09

Magoo


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
like image 135
Ian Avatar answered Sep 22 '22 16:09

Ian