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

  1. Posts : 10
    Windows 10 Home 64-bit
       12 Sep 2017 #1

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

    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 ComputerSystem Spec

  2.    12 Sep 2017 #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

    (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.

    This command would help you obtain a string or number representing the day of the week
    Click image for larger version. 

Name:	1.jpg 
Views:	2 
Size:	133.9 KB 
ID:	152887
      My ComputerSystem Spec

  3.    12 Sep 2017 #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.

    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%


    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

    :: put your processing here
    echo %DayOfWeekName%

    :: put your processing here
    echo %DayOfWeekName%

    :: put your processing here
    echo %DayOfWeekName%

    :: put your processing here
    echo %DayOfWeekName%

    :: put your processing here
    echo %DayOfWeekName%

    :: put your processing here
    echo %DayOfWeekName%

    :: put your processing here
    echo %DayOfWeekName%
    Last edited by cereberus; 12 Sep 2017 at 09:02.
      My ComputerSystem Spec

  4. Posts : 10
    Windows 10 Home 64-bit
    Thread Starter
       14 Sep 2017 #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 ComputerSystem Spec

  5.    14 Sep 2017 #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 ComputerSystem Spec


Related Threads
I cannot get it to work that Windows Task Scheduler closes a program each day. I have added this path C:\Dir Lw C\Programme\Rainlendar - Dirks Kalender (Daten etc.)\RainlendarPro schließen.lnk to a new task and the ink file is containing this...
Task Scheduler: Start a Program with Office in Microsoft Office and 365
Does anyone know how to have Task Scheduler start a program to run with the launch of ANY Office application? I have a registry edit which will enable the black theme in Office 2016. It needs to be run each time any Office app opens. I can do...
Task Scheduler doesn't run program in Performance & Maintenance
I'm running a task schedule to run a program at a certain time. It worked great in windows 7 but since I upgraded to 10 nothing happens when the task is run. I've run SFC and Dism see below and no problems found. C:\WINDOWS\system32>sfc /scannow...
Hi, I'm trying to set up a task using Task Scheduler to run a game which is on one of my secondary drives, drive F: - I have Windows 10 installed on the C: drive. The problem I'm having is Task Scheduler doesn't seem able to start a program if...
I have installed Speedfan and it won't run at the windows startup, so I tried to schedule it in task scheduler, I am not familiar with using it and wondered if there is a guide for W10 64 anywhere or if anyone can tell me how? Many thanks in...
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 01:48.
Find Us