locked
Need help with Windows scheduler options RRS feed

  • Question

  • I use Windows scheduler to run BAT files using the "At startup" option.  Is it possible to insert some script into the BAT file that will prevent it from running on weekends?

    If not, is there some way to accomplish this while still being able to run at startup the rest of the time?

    All help appreciated.

    Wednesday, August 5, 2020 6:05 PM

All replies

  • You can insert a condition at the beggining of your script that will check the day of the week : If the dayofweek is > 5, that means it's saturday or sunday, then you STOP the script.

    You can get the day of the week with following line in batch :

    for /f %%a in ('wmic path win32_localtime get dayofweek /format:list ^| findstr "="') do (set %%a)

    The variable %dayofweek% is an integer representating the day of the week : 1= Monday, 7=Sunday

    Then you can build your condition to run the script or not :

    if %dayofweek% leq 5 (

    ...your code

    )else (exit)

    Hope it helps.


    Wednesday, August 5, 2020 9:20 PM