Windows Task Sheduler with specific day excluding weekends

1

1

With Windows Task Sheduler I have to make a task which will be executed on 6th day of every month except weekends. If 6th is day of weekend, task will be executed on Monday (7th or 8th). I've expected making of two rules with AND logic which one is allowing 1st Mo-Fr and second is disallowing days 1-5 but this is not supported.

Am I missing something or how to easily solve this without installing any huge 3rd party software?

I found DOS/Windows cmd date can't parse date so I can't compare its output, so maybe PowerShell (never used it yet) or cygwin can solve it but it seems to be very dirty to call unix enviroment for checking the date and if it not fail then calling win32 application again.

dmnc

Posted 2014-04-01T15:21:29.227

Reputation: 398

Please explain your downvotes! – dmnc – 2014-04-30T11:30:58.157

Answers

2

Use Powershell or VBA as your task target, and schedule the task to run daily.

Powershell idea to get you started:

$dayName = Get-Date -Format dddd
$dayNum = Get-Date -Format dd

if (($dayNum -eq "06" -and $dayName -ne "Saturday" -and $dayName -ne "Sunday") -or ($dayName -eq "Monday" -and ($dayNum -eq "07" -or $dayNum -eq "08"))) { 
    RunTask()
}

Ƭᴇcʜιᴇ007

Posted 2014-04-01T15:21:29.227

Reputation: 103 763

nice and clean... – dmnc – 2014-04-30T11:21:12.277

1

I'm sorry I cannot contribute the exact code, as I'm at work with limited time/resources, but I believe I have your solution.

Schedule a batch script every 6 of the month. This batch will parse the 'date /T' command from the command line.

If the 3 letter day from "date" = Mon, Tue, Wed, Thu, Fri... execute your task
If the 3 letter day from "date" = Sat, execute your task with 48hour delay (may need to make separate task with this delay)

Same with 'Sun' but you will need 24 hour delay.
I hope this puts you on the path to your solution.

EDIT: you'll want this for the date! http://www.dostips.com/DtTipsStringManipulation.php#Snippets.LeftString

Wutnaut

Posted 2014-04-01T15:21:29.227

Reputation: 724

+1 for that link, DOS string manipulation can solve this – dmnc – 2014-04-30T11:21:51.667

-1

You may want to check the details of the SchTasks command in Windows (link below). It allows a number of configuration options which should serve your purpose well. See the options /mo and /d especially.

http://technet.microsoft.com/en-us/library/cc772785(v=ws.10).aspx

nirav

Posted 2014-04-01T15:21:29.227

Reputation: 1

Can you provide some example command? Because as I said this is probably impossible in the stock task scheduler. Please improve your answer otherwise this is for downvote. – dmnc – 2014-04-01T15:35:02.363

I'm not joking man. This is the example? C/P of syntax? With example I meant working piece of 'code' and with working I mean configuration which runs on on 6th of every month while this day is not Saturday and not Sunday. // Edit: he deleted his comment with mentioned "example"... – dmnc – 2014-04-01T15:46:20.837

If you are making your own april fools with creating new profiles and abusing other people, please stop, it's not such cleaver as you think and your accounts will be terminated. Seriously. – dmnc – 2014-04-01T15:49:35.937

First - Stop flaming someone trying to help you. Second - The text pasted in the comments area got posted by an inadvertent ENTER, instead of a SHIFT-ENTER.

Go ahead, do it yourself now. – nirav – 2014-04-01T15:53:37.903

>

  • it's not flaming 2) next time do not delete comments which has been replied 3) sorry but I can't see any AND/OR rule in the scheduler syntax, do you? Yes, so plase write some example syntax 4) if something about the question is unclear to you, ask me and I'll explain.
  • < – dmnc – 2014-04-30T11:26:06.433