Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict windows tasks to weekdays only?

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.

like image 959
membersound Avatar asked May 04 '16 10:05

membersound


People also ask

How to disable scheduled tasks on the Task Scheduler?

The same way tasks are enabled on the task scheduler is the same way users can also disable them. Here’s how to disable scheduled tasks using the Task Scheduler: Step 1: Click on the Windows button at the bottom-left of your PC screen. Step 2: Scroll to Windows Administrative Tools and click on the drop-down arrow to unveil the different tools.

How to schedule a task to end on a holiday day?

Well, One way I see to do this is to the task to end on a holiday, then have a second task starting on the next working day, and ending that task the next holiday. Rinse and repeat per holiday. The newer versions of task scheduler does seem to let you string events together, but I don't see any option not to run a task on a specific day.

Can task SCH run every 15 minutes but only during a window?

Can Task Sch. be setup to run every 15 minutes but only during a certain window of time. So I could set it up to run every 15 min, but only from 5pm to 5am -- and not run at all from 5am to 5pm? Set a daily schedule starting at 5pm. In the Advanced dialog, click Repeat task, then specify Every=15 minutes, Until:Time=5am.

How do I set a daily schedule for repeating tasks?

Set a daily schedule starting at 5pm. In the Advanced dialog, click Repeat task, then specify Every=15 minutes, Until:Time=5am. Edit: The above instructions are for Windows 2003 Server or XP.


2 Answers

  1. click Weekly (NOT Daily)
  2. Choose the days you want
like image 72
alex Avatar answered Sep 27 '22 22:09

alex


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!

like image 42
CherryDT Avatar answered Sep 28 '22 00:09

CherryDT