GoldMath
GoldMath

Reputation: 79

Auto-restart a Program every hours with cooldown

I'm looking for a script who can realize this sequence.

  1. Close the Program every three hours;
  2. Wait 30 seconds;
  3. Relaunch the Program;

Can you help me manage this problem ? Thanks a lot !

Regards,

Upvotes: 3

Views: 16319

Answers (3)

09stephenb
09stephenb

Reputation: 9806

There is a post here Batch file - restart program after every 20 minutes

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

Upvotes: 6

Captain Barbossa
Captain Barbossa

Reputation: 1177

@set /A _tic=%time:~0,2%*3600^
            +%time:~3,1%*10*60^
            +%time:~4,1%*60^
            +%time:~6,1%*10^
            +%time:~7,1% >nul

:: actual script

@set /A _toc=%time:~0,2%*3600^
            +%time:~3,1%*10*60^
            +%time:~4,1%*60^
            +%time:~6,1%*10^
            +%time:~7,1% >nul


: loop
 @set /A _elapsed=%_toc%-%_tic
 @echo %_elapsed% seconds.
  :: check for elapsed time here

  :: kill the app
  taskkill /im <yourappname>
  :: sleep for some time
  timeout /T 10

  :: start again
  start <yourappname>

goto loop

Upvotes: 1

pentadecagon
pentadecagon

Reputation: 4847

Python is an option here:

import subprocess, time

while True:
    proc=subprocess.Popen("something.exe")
    time.sleep(3*60*60) # 3 hours
    proc.kill()
    time.sleep(30)  # 30 seconds

Upvotes: 3

Related Questions