How to run a bat file at specified day/time?

17,414

There's the windows scheduler, but I doubt you are going to be able to do a schedule that advanced with just the windows scheduler.

What I would do is write the scheduling logic (e.g. when you want your batch file to run) in some high level language (C#, JAVA, etc.), then call that program at the beginning of your batch file to see if it's a date you care about.

The batch file could be set up to run each day (or multiple times per day if needed) using the windows scheduler, but it would only do the "real stuff" if your C#/JAVA program indicated that it was a date you cared about.

Share:
17,414
Nemo
Author by

Nemo

Updated on June 04, 2022

Comments

  • Nemo
    Nemo almost 2 years

    I have a bat file that I want to run at specific day/time in each quarter for a year. I m new to command line and I know how to run it via a task scheduler, which is very easy.

    Let's say for each quarter, for 1st and 2nd month, my bat file should run at alternative weeks. For the third month of a quarter, it should run weekly. Possible time would be early morning 6:00 a.m. How would I do it? Please let me know. Thanks.

  • Nemo
    Nemo almost 12 years
    Thanks dcp for your i/p. If windows Scheduler is a better way to do it- schedule it that advanced, i will do it that way. I was just thinking of creating a vbs script that would call and run my bat file on specified date-time as mentioned in my question. That way, I won't have to schedule my bat file to run it multiple times via scheduler. Please let me know if that's doable.? Thanks again.
  • dcp
    dcp almost 12 years
    @Nemo - The bat file will still need to run at least once a day, and you can use the scheduler for that. If your script won't need to run at different times, you can just have it run the same time every day. You can probably code the date checking logic in vbs, as long as vbs has calendar objects, etc. where you can figure out if it's the first quarter, etc. But yes, I think it's doable.
  • Nemo
    Nemo almost 12 years
    Thanks Aacini for your effort. I would love to understand your code. I have less experience in writing a batch file. Some additional comments to each line would help me better understand it. Just a thought. Thanks again. :) Your help is greatly appreciated. :)
  • Admin
    Admin over 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.