Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Scripting the creation of complex Scheduled Tasks

Reply
 
Old 07-14-2009   #1 (permalink)
Mike Short


 
 

Scripting the creation of complex Scheduled Tasks

Hi,

I want to script the creation of a scheduled task with multiple
schedules enabled, to run on XP and W2K3.

An example schedule: I have a task I want to run at 8pm Mon-Thu, 10pm
Fri and at 8am on the last day of each month.

This can be done easily enough from the Scheduled Tasks Applet (just
check the Multiple Schedules checkbox from the task properties) but I
can't find a way to script this. Well, OK, SendKeys or AutoIt or
similar but that needs an interactive session.

AT, SchTasks and Win32_ScheduledJob only seem to support a single
schedule.

I know I could create multiple tasks running the same process, each
with it's own schedule but the above really is an example. I know I
could create 3 tasks for the example but the real problem I have could
potentially require a dozen or more schedules.

Anyone got another solution?

My System SpecsSystem Spec
Old 07-14-2009   #2 (permalink)
Bernie


 
 

Re: Scripting the creation of complex Scheduled Tasks

From your example data, all tasks are starting on the hour. If that's
consistant then you could have the script run every hour, on the hour, and
check what needs to be done at that time. That would move the multiple
operations from Scheduled Tasks and out into your script.

Depending on how large your script gets and if you have trouble with the
hourly testing for operation, maybe you could have a small tight script that
checks for things to do that hour and then it envolkes another script that
is longer and has all the operations in it.

If you use Scheduled Tasks you said it could require a dozen or more. How
many more? A dozen entries in the Task Scheduler I think would be much
easier to manage than you reinventing the scheduling in your script. Have
you tried the Task Scheduler solution?

Bernie


"Mike Short" <michael.short@xxxxxx> wrote in message
news:bf7cb506-8dc2-4025-830a-e33ce17d34d7@xxxxxx
Quote:

> Hi,
>
> I want to script the creation of a scheduled task with multiple
> schedules enabled, to run on XP and W2K3.
>
> An example schedule: I have a task I want to run at 8pm Mon-Thu, 10pm
> Fri and at 8am on the last day of each month.
>
> This can be done easily enough from the Scheduled Tasks Applet (just
> check the Multiple Schedules checkbox from the task properties) but I
> can't find a way to script this. Well, OK, SendKeys or AutoIt or
> similar but that needs an interactive session.
>
> AT, SchTasks and Win32_ScheduledJob only seem to support a single
> schedule.
>
> I know I could create multiple tasks running the same process, each
> with it's own schedule but the above really is an example. I know I
> could create 3 tasks for the example but the real problem I have could
> potentially require a dozen or more schedules.
>
> Anyone got another solution?

My System SpecsSystem Spec
Old 07-14-2009   #3 (permalink)
Mike Short


 
 

Re: Scripting the creation of complex Scheduled Tasks

> Depending on how large your script gets and if you have trouble with the
Quote:

> hourly testing for operation, maybe you could have a small tight script that
> checks for things to do that hour and then it envolkes another script that
> is longer and has all the operations in it.
>
That's a good idea. If no other solution presents itself, that would
certainly work. Actually, something tells me that this is what I will
end up having to do.
Quote:

> If you use Scheduled Tasks you said it could require a dozen or more. How
> many more? A dozen entries in the Task Scheduler I think would be much
> easier to manage than you reinventing the scheduling in your script. Have
> you tried the Task Scheduler solution?
The "how many more" is, er, probably not many more but the scheduling
may need to be adapted. A dozen task scheduler entries isn't a
problem until you want to suspend execution. I'd need to write
another enable/disable script to make sure I got them all.

I have tried the manual Task Scheduler solution and, yes, it works
but... I have hundreds of target servers spread across the globe,
needing different TZs and (depending on the working week there)
different schedules. Automation is the watch-word here. It is a
scripting question, after all.
My System SpecsSystem Spec
Old 07-14-2009   #4 (permalink)
Larry Serflaten


 
 

Re: Scripting the creation of complex Scheduled Tasks


"Mike Short" <michael.short@xxxxxx> wrote
Quote:

> Anyone got another solution?
You could bit flag the tests and assign masks to the tasks.

For example, you run a script every hour that has multiple tests.
If its 8pm on a Mon-Thu, bit 1 of the schedule flag gets set.
If its 1pm on a Friday, bit 2 gets set.
If its 8am on the last day of the month, bit 3 gets set.

Then you keep a list of tasks with their associated schedule masks.
Any task that needs to run Mon-Thur, has bit 1 of its mask set.
Any task that needs to run 1pm on Friday has bit 2 of its mask set.
And so on. If it needs to run at both those times, then both bits are
set, etc...

Once your hourly script has run you have a schedule flag you can
compare (using And) against the task masks. Any tasks whose
mask has the same bit(s) set as the flag needs to run at that time.

You could try to organize it, or you could get more complex (using
and And mask and an Or mask) or you could just go ad hoc, adding
new tests (and bit positions) as new schedules emerge. Anything you
try is not going to be trivial, but certainly doable, depending on how
much effort you want to spend at it....

Just another idea....
LFS



My System SpecsSystem Spec
Old 07-15-2009   #5 (permalink)
Larry Serflaten


 
 

Re: Scripting the creation of complex Scheduled Tasks


"Mark D. MacLachlan" <markdmac@xxxxxx> wrote
Quote:

> I think the only real solution you will have is to schedule your task
> multiple times for each day and time that you want it to run.
Quote:

> CreateTask strComputer,"Notepad.exe","1300",Monday or Tuesday
> CreateTask strComputer,"Notepad.exe","1100",Thursday or Friday
How would that pick up something like, 8am on the last day of the month?
(or the last Friday of the month, etc)

While I noticed you used bit flags for the days of the week, I still think the OP
would need to create separate tests for each schedule and use a flag to indicate
the scheduled task(s) need to run. To do that, an overall manager would need to
run every hour to perform the tests....

LFS


My System SpecsSystem Spec
Old 07-15-2009   #6 (permalink)
Mark D. MacLachlan


 
 

Re: Scripting the creation of complex Scheduled Tasks

Larry Serflaten wrote:
Quote:

>
> "Mark D. MacLachlan" <markdmac@xxxxxx> wrote
>
Quote:

> > I think the only real solution you will have is to schedule your
> > task multiple times for each day and time that you want it to run.
>
Quote:

> > CreateTask strComputer,"Notepad.exe","1300",Monday or Tuesday
> > CreateTask strComputer,"Notepad.exe","1100",Thursday or Friday
>
> How would that pick up something like, 8am on the last day of the
> month? (or the last Friday of the month, etc)
>
> While I noticed you used bit flags for the days of the week, I still
> think the OP would need to create separate tests for each schedule
> and use a flag to indicate the scheduled task(s) need to run. To do
> that, an overall manager would need to run every hour to perform the
> tests....
>
> LFS
Larry the code I posted was just a sample and would require further
tweaking to setup specific dates and times. The key issue here I think
is that the desire is to use a scripted solution while also utilizing
the advanced features of the GUI interface which is not script enabled.

One could grab the last day of the month in the following fashion:

For M = 2 To 13
If M < 13 Then
FirstOfMonth = M & "/1/" & Year(Date)
LastOfMonth = CDate(FirstOfMonth) -1
WScript.Echo LastOfMonth
Else
LastOfMonth = "12/31/" & Year(Date)
WScript.Echo LastOfMonth
End IF
Next

There might be a more elegant way of doing that but that is what comes
to my mind at the moment.

Based on the data provided, I believe the requested solution is not
possible as a scripted solution. Instead Mike would need to rethink
the requirements and architect around what options are possible in the
AT command.

A suggested alternative would be to use AT to schedule the running of a
VBScript that could then make the inteligent decisions that the AT
command cannot.

Regards,

Mark D. MacLachlan

My System SpecsSystem Spec
Old 07-15-2009   #7 (permalink)
Larry Serflaten


 
 

Re: Scripting the creation of complex Scheduled Tasks


"Mark D. MacLachlan" <markdmac@xxxxxx> wrote
Quote:

> A suggested alternative would be to use AT to schedule the running of a
> VBScript that could then make the inteligent decisions that the AT
> command cannot.
Bingo



My System SpecsSystem Spec
Old 07-16-2009   #8 (permalink)
Dr J R Stockton


 
 

Re: Scripting the creation of complex Scheduled Tasks

In microsoft.public.scripting.vbscript message <OCtRm4ZBKHA.1488@xxxxxx
NGP03.phx.gbl>, Wed, 15 Jul 2009 15:46:52, Mark D. MacLachlan
<markdmac@xxxxxx> posted:
Quote:

>
>One could grab the last day of the month in the following fashion:
>
>For M = 2 To 13
> If M < 13 Then
> FirstOfMonth = M & "/1/" & Year(Date)
> LastOfMonth = CDate(FirstOfMonth) -1
> WScript.Echo LastOfMonth
> Else
> LastOfMonth = "12/31/" & Year(Date)
> WScript.Echo LastOfMonth
> End IF
>Next
>
>There might be a more elegant way of doing that but that is what comes
>to my mind at the moment.
There is. Perhaps you missed my microsoft.public.scripting.vbscript
message <W57ScIODO3UKFwCX@xxxxxx> of Tue, 7
Jul 2009 17:10:43. Consider it, sig, and :-

S = "<pre>"
for J = 1 to 16
S = S & J & " " & Day(DateSerial(2008, J+1, 0)) & VBCRLF
next
document.write S & "</pre>"
' It is convenient for me to write for a web page;
' changes for WSH should be easy enough. For full dates, omit Date().

Also, your way uses a vile FFF date string, and gives me the final date
in an alien format (my WinXP is set for ISO dates). That difference can
be avoided by changing one of your lines to
LastOfMonth = CDate("12/31/" & Year(Date))

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm vb-dates.htm pas-time.htm critdate.htm etc.
My System SpecsSystem Spec
Old 07-17-2009   #9 (permalink)
Mike Short


 
 

Re: Scripting the creation of complex Scheduled Tasks

OK, I think the way forward here is to schedule a task that is invoked
every hour and then use the logic in the task to see whether or not it
should do anything at that point.

Thanks for all your input, it's been interesting and, hey, for once I
didn't walk away feeling dumb for having missed something really
obvious.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
scheduled tasks with WMP or MCE Vista General
scheduled tasks Vista General
Scheduled Tasks Vista General
Scheduled Tasks Vista performance & maintenance
Re: scheduled tasks Vista account administration


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46