Schedule a task with 'AND' and 'WAIT' conditions with Windows Tasks scheduler - windows

I want a task to start when both of these conditions are met:
Once a week, every week. like every friday at 3PM
When a session is started and not locked
I know how to do 1 OR 2, but I'm not able to schedule the task only when the 2 conditions WILL meet.
In other words, IF the session is locked at 3PM, I don't want the task to start now, but I don't want it to be skipped! I want the task to wait for the session to be opened (or unlocked) and then to start immediately.
So if a session is unlocked only Saturday morning and not Friday, then the task shall execute on Saturday; and then it will repeat the same process next Friday.
I am not sure how to correct specify the conditions such that:
If its Friday at 3 PM and the session is unlocked; the task should run.
If the interval (Friday at 3 PM) has passed, but the task has not run (because the session was not available); then it should run at the very first instance the session is available, irrespective of the date and time.

Related

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.
click Weekly (NOT Daily)
Choose the days you want
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!

Autosys job suspension for a specific hour in a day

I need to schedule a job in Autosys in such a way that
it runs every 20 min everyday
it does not run for a specific time (say 01:00 to 02:00) everyday
What is the correct way to schedule this?
Try this....
date_conditions: 1
days_of_week: all
start_mins: 00,20,40
run_window: "02:00-01:00"
You would need to set up 2 jobs, with all the same parameters (except the job name, of course, which has to be unique), except one will have a run_window before the period of time you don't want it to run, and the other job will start up at the end of the time it is not to run:
Job A: run_window: 08:00-12:00
Job B: run_window: 13:00-16:00

run a script every 4 hours with task scheduler

I have windows 2008 task scheduler I set up a PHP script to run like this
C:\php\php.exe -f etc...
In windows task scheduler I can only schedule daily or hourly how can I configure it to run every 4 hours?
In Windows Server 2008/2008R2 you can set task to repeat every number of hours you want, corresponding drop down menu just present you with 1 hour option to select, but you can type in any number of hours you need (see screenshot below).
You could just set it up to run every hour, and at the beginning of the PHP script, check the current time, and exit if the current hour modulus 4 wasn't zero.
Where it says "repeat task every", you may also just be able to change "1 hour" to "4 hours" (it's not in the dropdown, so just type it in). You can do this in Windows 7, I'm not sure about Windows Server 2008.

Quartz.NET: Need CronTrigger on an iStatefulJob instance to *delay instead of skip* if running job while schedule matures

Greetings, your friendly neighborhood Quartz.NET n00b is back!
I have a Windows Service running iStatefulJob instances on a Quartz.NET CronTrigger based schedule scheme... The CRON String used to schedule the job: "0 0/1 * * * ? *"
Everything works great. However, if I have a job that is set to run, say, at the X:00 mark of every minute, and that job happens to run for MORE than a minute, I notice that the subsequent job runs IMMEDIATELY after the job is finished executing, rather than waiting until its next scheduled run, effectively "queuing" up instead of merely skipping the job till it's next scheduled run.
I put in the trigger a CronTrigger MisfireInstruction of DONOTHING, but the exact same thing happens when a job overruns its next scheduled execution schedule.
How do I get an iStatefulJob instance to merely SKIP a scheduled execution trigger if it is currently running, rather than have it delay it until the first execution completes?
I explicitly set the trigger.MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;
...But instead of "doing nothing", for a job scheduled to run every minute that takes 90 seconds to complete, I experience the following execution log:
Job runs at 9:00:00am, finishes at 9:01:30am <- job runs for 1:30
Job runs at 9:01:30am, finishes at 9:03:00am <- subsequent job that should have run at 9:01:00
Job runs at 9:04:00am, finishes at 9:05:30am <- shouldn't this one have run at 9:03:00?
Job runs at 9:05:30am, finishes at 9:07:00am <- subsequent job that should have run at 9:05:00
Job runs at 9:08:00am, finishes at 9:09:30am <- shouldn't this have run at 9:07:00?
... it seems like it runs correctly the first time, on the minute... delays for 30 seconds as the 90 second job execution time expires, and then, instead of waiting till the NEXT full minute, EXECUTES IMMEDIATELY at the 30 second mark... Doubly odd, is that it then finishes the SECOND job on the minute mark, but waits till the NEXT minute mark to execute instead of running it back-2-back...
Pretty much seems like it works correctly EVERY OTHER RUN, when it is not running on the :30 marks...
What's the best way to get a job not to delay/queue, but to just SKIP until it is idle and the next schedule matures?
EDIT: I tried going back to iJobs instead of iStatefulJobs using the same DONOTHING trigger misfire instruction, but the job executes EVERY MINUTE despite the prior execution being still active. I can't seem to get it to skip a scheduled run if it is currently running with either iJob or iStatefulJob...
EDIT#2: I think that my triggers are NEVER misfiring, which is why DoNothing as a misfire instruction is useless... Given that's the case, I guess I need another mechanism to detect if a job instance of a schedule is running to ensure the job SKIPS its next execution until its following scheduled time rather than delaying it until first instance completion...
EDIT3: I tried adding an element to the iStatefulJob jobdatamap called "IsRunning"... I set it to TRUE when the execute sequence starts, and then return it to false after job completion. Before executing, it checks the element, which is apparently persisted between jobs, and prematurely quits the execution (logging "JOB SKIPPED!") if it detects it to be true... This unfortunately doesn't work, for probably obvious reasons: If the jobs are running following the bulleted schedule above, then the job is never SIMULTANEOUSLY running along with itself, as it is delaying the run till the job ends, so this check is useless. According to documentation, returning to iJob from iStatefulJob would not help here as the jobdatamap is only persisted between jobs in the Stateful job type...
I still haven't solved how to SKIP a scheduled job instead of delaying it till it's current iteration completes... If anyone has ideas, you're a lifesaver! :)
It should be caused by misfireThreshold of RAMJobStore (http://quartznet.sourceforge.net/apidoc/topic2722.html).
The time span by which a trigger must
have missed its next-fire-time, in
order for it to be considered
"misfired" and thus have its misfire
instruction applied.
It is 60 seconds by default. So job isn't considered as "misfired" until it is late for more than misfiredThreshold value.
To resolve the problem just decrease this threshold (below code sets to 1 ms):
...
properties["quartz.jobStore.misfireThreshold"] = "1";
...
schedulerFactory = new StdSchedulerFactory(properties);
It should resolve the issue.

Scheduling a task to run at the end of every month. (Windows Server 2003 - Scheduled Tasks)

I need to schedule a task to run on the last night of each month, on a Windows 2003 Server.
I see that you can schedule it to run on the "first or last Mon-Fri", or even on the nth day of each month - but, not how to get it to run on the last day (regardless of day of the week or number).
Thanks in advance.
Note: I did check "How do you schedule tasks in Windows?", etc...
Looks like you have to set up multiple schedules for your task. One schedule for the months with 31 days, another for those with 30, and one more for February. See this: http://support.microsoft.com/kb/936627
I do it a little differently - I run one task every day but since the task is in vbscript - I do this:
DIM datecur, datefut
datecur = DATEPART("m",NOW())
datefut = DATEPART("m",NOW()+1)
If (datecur <> datefut) then
'insert code you want to run here
end if
Simple and it works - hope this helps someone
As of November 2022, much newer Windows version (2019)
I see this option in Triggers:
WinScheduler Task Triggers
Begin the task: On a schedule
Settings:
Monthly
On: Last > then select All weekdays

Resources