10

I have a task that triggers on "user session logon". I now want to restrict that task to fire only on weekdays, and being ignored on the weekend.

Is that possible?

Sidenote: I cannot use the trigger on schedule as I do not want to run the task periodically, but only on logon, and only on weekdays.

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • https://superuser.com/questions/513676/is-it-possible-to-schedule-a-task-only-on-working-days/513679 – 472084 Apr 13 '17 at 16:43

2 Answers2

25
  1. click Weekly (NOT Daily)
  2. Choose the days you want
alex
  • 277
  • 3
  • 6
3

As far as I understand, this is not possible using the task scheduler alone.

You could use a piece of VBScript to achieve this.

Set up a file, e.g. mytask.vbs, like this:

If DatePart("w", Date, vbMonday) < 6 Then
    Set Shell = CreateObject("WScript.Shell")
    WScript.Quit(Shell.Run("C:\Windows\System32\notepad.exe", 10, True))
End If

Replace notepad by the task you actually want to run. What this things does is: It checks whether the current day is Mo-Fr (this is done by specifying the start of the week as Monday, so DatePart will return values from 1=Monday to 7=Sunday, and then we're checking if it's below 6), and if yes, it runs a certain program, waits for it to finish and forwards its exit code. (The magic number 10 here means that it will respect whatever setting for window display (normal, maximized, minimzed) was passed by the task scheduler, if any, and also forward it to the program.)

Then you can create a scheduled task with a logon trigger only, which runs wscript.exe /e:vbscript c:\path\to\your\mytask.vbs. That's it!

CherryDT
  • 25,571
  • 5
  • 49
  • 74