Windows 10 Task Scheduler: How to program non-routine trigger


  1. Posts : 14
    Windows 10 Home 64-bit
       #1

    Windows 10 Task Scheduler: How to program non-routine trigger


    Hi
    I am trying to set up a task to be triggered on the second day of every month, but not if that day is a Saturday.

    Can anyone help please?
      My Computer


  2. Posts : 43,027
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Hi, you'll have realised you can't do that directly with te task scheduler, although you can of course start a task on the 2nd day of each month.

    I would create the task so as to launch a small Autohotkey script, which would basically do this:

    Assign today = value representing the current day ; Mon Tue Wed etc
    If today NE Saturday then
    Run the task you want to run ; Executed except on Saturdays
    Exit

    (That's not a script, merely indicates the very simple logic).

    Autohotkey is a well supported free scripting language with a good forum and help file.
    https://www.autohotkey.com/

    This command would help you obtain a string or number representing the day of the week
    Windows 10 Task Scheduler: How to program non-routine trigger-1.jpg
      My Computers


  3. Posts : 15,499
    Windows10
       #3

    You could create a batch file (run daily) that returns day of week, jumps to specific location depending on day of week, then executes what ever command you want (assuming it can be executed from a command line)

    you can download a batch file containing text below

    Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.

    or create own.


    I take no credit for this - it is an amalgamation of several batch files I found on web,

    I tried it and it returns Tue which is today's date.
    --------------------------------------------------------------------------------------------

    @echo
    setlocal enabledelayedexpansion
    set DoW=Sun Mon Tue Wed Thu Fri Sat
    set /a Line=0
    for /f "tokens=1-9" %%a in ('wmic Path Win32_LocalTime Get Day^,DayOfWeek^,Hour^,Minute^,Month^,Quarter^,Second^,WeekInMonth^,Year ^| find /v ""') do (
    set /a Line += 1
    if "!Line!"=="1" (set VarA=%%a&set VarB=%%b&set VarC=%%c&set VarD=%%d&set VarE=%%e&set VarF=%%f&set VarG=%%g&set VarH=%%h&set VarI=%%i)
    if "!Line!"=="2" (set !VarA!=%%a&set !VarB!=%%b&set !VarC!=%%c&set !VarD!=%%d&set !VarE!=%%e&set !VarF!=%%f&set !VarG!=%%g&set !VarH!=%%h&set !VarI!=%%i)
    )
    for %%a in (Month Day Hour Minute Second) do (if !%%a! LSS 10 set %%a=0!%%a!)
    set /a DoWIndex = DayOfWeek + 1
    for /f "tokens=%DoWIndex%" %%a in ("%DoW%") do set DayOfWeekName=%%a
    REM *** At this point, the variables DayOfWeekName, Day, DayOfWeek, Hour, Minute, Month, Quarter, Second, WeekInMonth, and Year are set.
    REM *** Month, Day, Hour, Minute, Second have leading zeros if less than 10.
    echo DayOfWeekName: %DayOfWeekName%

    pause

    if %DayOfWeekName%==Mon goto :mon
    if %DayOfWeekName%==Tue goto :tue
    if %DayOfWeekNamegoto :wed
    if %DayOfWeekName%==Thu goto :thu
    if %DayOfWeekName%==Fri goto :fri
    if %DayOfWeekName%==Sat goto :sat
    if %DayOfWeekName%==Sun goto :sun

    :mon
    :: put your processing here
    echo %DayOfWeekName%
    pause
    exit

    :tue
    :: put your processing here
    echo %DayOfWeekName%
    pause
    exit

    :wed
    :: put your processing here
    echo %DayOfWeekName%
    pause
    exit

    :thu
    :: put your processing here
    echo %DayOfWeekName%
    pause
    exit

    :fri
    :: put your processing here
    echo %DayOfWeekName%
    pause
    exit

    :sat
    :: put your processing here
    echo %DayOfWeekName%
    pause
    exit

    :sun
    :: put your processing here
    echo %DayOfWeekName%
    pause
    exit
    Last edited by cereberus; 12 Sep 2017 at 09:02.
      My Computer


  4. Posts : 14
    Windows 10 Home 64-bit
    Thread Starter
       #4

    Dear Dalchina and Cereberus

    Thank you both for your suggested solutions for my task scheduling problem.

    When submitting my post, in the interests of brevity I did not mention that the task involved is alreading operating from Task Scheduler under other simpler triggers, and I was just hoping to be able to add an additional trigger.

    However, at Task Scheduler appears to have no facility for subjecting triggers to logical processes, maybe I should look at scripting the whole thing.

    Thank you also Dalchina for your reference to Autohotkey. I have downloaded it and it looks like a good resource to have.

    You both contributed to alerting me to the possibility of scripting the triggers, for which I am grateful, and although I am not too experienced in scripting I am nonetheless happy to mark my post as solved.
      My Computer


  5. Posts : 43,027
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #5

    Good.. Autohotkey is a remarkable scripting tool. You can use it for
    - very simple scripts (like this one, which should be just 4 or 5 lines at most)
    - writing complete programs
    - manipulating existing Windows - e.g. clicking buttons, testing for presence, closing annoying popups etc etc
    (that's supported by tools which let you inspect many window parameters so you can find the identity of elements in a window)

    Scripts can be run as the source code alone (ahk files) or compiled with 1 click to produce an exe file.

    There is a language sensitive editor to help writing scripts
    SciTE4AutoHotkey Editor
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 07:59.
Find Us




Windows 10 Forums