1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

A little tricky

Discussion in 'DOS/Other' started by Disheer, Dec 20, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. Disheer

    Disheer Thread Starter

    Joined:
    Dec 17, 2010
    Messages:
    9
    I have been looking and a small time employer of mine asked me if I could do him a favor and since it is above my head a little I thought I would ask people who know.

    My part-time Employer asked me if I could make a batch that would run and by running would check to see if a program is not running and start it. This part I can do. Then He wants me to add something that will shut down the program and rerun it 10 minutes later (at a certain time each day.) This is where I get lost.

    I need it to run on a loop so it does not need to be started every 30 minutes.


    The batch I have so far is as follow

    tasklist /FI "IMAGENAME eq Acc.exe" 2>NUL | find /I /N "Acc.exe">NUL
    if "%ERRORLEVEL%"=="0" echo Programm is running


    But I can not find a way to make it wait 30 minutes and check again or to run it if not running.


    the exact script he is wanting goes as follows

    1. check time
    2. if 30 minutes check process running
    3. if not running start process
    4.at 9:01 pm shut down process and restart it at 9:11
    5. loop it.

    Not sure if possible if so Please help.

    I am still very new to batch. I said I would try as I need the money.
     
  2. Elvandil

    Elvandil

    Joined:
    Aug 1, 2003
    Messages:
    51,988
    Windows Task Scheduler. That is what it is for.
     
  3. Disheer

    Disheer Thread Starter

    Joined:
    Dec 17, 2010
    Messages:
    9
    Task scheduler will only start and stop the funtion ones a day week month or just once. I have to find a way to check it every few minutes.
     
  4. TheOutcaste

    TheOutcaste

    Joined:
    Aug 7, 2007
    Messages:
    9,028
    Use Task Scheduler, schedule it for Every day, then check the Repeat every box in the schedule Advanced properties dialog and set it to 30 minutes. Have this run at 11 minutes past the hour

    Use a second task to shutdown the program at 9:01 PM. When the first task runs at 9:11 PM it will restart the program.
    Or use a 3rd task to restart at 9:11 PM, and make sure the first task is not scheduled to run between 9:00 PM and 9:12 PM.

    If you are using Vista or Win 7 you can use the Timeout command to wait 10 minutes, but you have to make sure no one closes the Command Prompt window during that time.
     
  5. Disheer

    Disheer Thread Starter

    Joined:
    Dec 17, 2010
    Messages:
    9
    yes but The problem I am having is this runs off a Virtual Private Server or (VPS) where resources are limited. This would work to run the program but it would also need to shut it down so it did not run multiple occurences. I need to make sure the program is not running first then run if it is not running. Task manager can not do this. I tried. My employer want as little down time as possible and from the results we got his program gets the least use at the scheduled time he wants.
     
  6. TheOutcaste

    TheOutcaste

    Joined:
    Aug 7, 2007
    Messages:
    9,028
    I don't see how it would start multiple instances. If the program is running it does nothing.

    Save this batch file as StartIt.cmd
    It checks to see if the program is running. If not, it starts it.
    Create a Scheduled Task to run it every 30 minutes starting at 11 minutes past the hour:
    Code:
    @Echo Off
    Set _Program=Notepad.exe
    Tasklist /FI "IMAGENAME eq %_Program%"|findstr /I "%_Program%">NUL
    If %ErrorLevel%==0 Goto :EOF
    Start "" %_Program%
    Change the program name as needed. If you need to specify the path to the executable, add that to the Start command, not to the _Program variable.

    Save this batch file as KillIt.cmd
    If the program is running, it will end task on it. Depending on the program this could cause loss of data though. If the program has a way to shut down from the command line use that method instead.
    Create a Scheduled Task to run it at 9:01 PM
    Code:
    @Echo Off
    Set _Program=Notepad.exe
    Tasklist /FI "IMAGENAME eq %_Program%"|findstr /I "%_Program%">NUL
    If %ErrorLevel%==1 Goto :EOF
    TaskKill /IM %_Program%
    If you need to check to see if the program is running more frequently than every 10 minutes, just need to add a time check in the first file so that it exits if the time is between 9:01 and 9:10 PM. How to do that depends on your regional settings, which control the format of the %time% variable.
    If %time% outputs the time in a 24 hour format just use this to check:
    Code:
    If %time:~0,2%==21 If %time:~3,2% LSS 11 If %time:~3,2% GTR 00 Goto :EOF
     
  7. Disheer

    Disheer Thread Starter

    Joined:
    Dec 17, 2010
    Messages:
    9
    Thank you so much it works perfectly. I owe you big time.
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/969563

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice