2

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.

1
  • Please explain your downvotes!
    – dmnc
    Commented Apr 30, 2014 at 11:30

3 Answers 3

3

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()
}
1
  • nice and clean...
    – dmnc
    Commented Apr 30, 2014 at 11:21
0

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

1
  • +1 for that link, DOS string manipulation can solve this
    – dmnc
    Commented Apr 30, 2014 at 11:21
-2

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

5
  • 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
    Commented Apr 1, 2014 at 15:35
  • 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
    Commented Apr 1, 2014 at 15:46
  • 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
    Commented Apr 1, 2014 at 15:49
  • 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
    Commented Apr 1, 2014 at 15:53
  • 1) 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
    Commented Apr 30, 2014 at 11:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .