URGENT vbscript task scheduler

hi experts,
i need a script which creates a task scheduler job (no at command) with the following options:
Every  1 hour(s) from 08:00 for 10 hour(s) every Mon, Tue, Wed, Thu, Fri of every week starting 29.11.2004

if it is possible i should change all values with variables, for examble:
starttime = "08:00"
endtime = "18:00"
interval = "1h"     '1 hour
days = "Mon, Tue, Fri"
if starttime..........

please help this is really urgent!!!
Thanks in advance!!!
LVL 31
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
Here's one way to do it.  This solutions requires Edanmo's Task Scheduler component.  Follow this link () and scroll down the page until you find "Using the Task Scheduler from VB".  Click on the link there to download Schedule.zip.  Unzip the file and copy tskschd.dll into your System32 folder.  Register the dll (i.e. regsvr32 tskschd.dll) and you'll be ready to use the code below.  This is the only solution I know of for accessing the task scheduler using VB.

I tested this in my environment and it worked properly.

Const Sunday = 1, Monday = 2, Tuesday = 4, Wednesday = 8, Thursday = 16, Friday = 32, Saturday = 64
Const WeeklyTrigger = 2
Dim oSchedule, oTask
Set oSchedule = CreateObject("TaskScheduler2.Schedule")
Set x = oSchedule.CreateTask("MyTaskName")  '<- Replace with the name you want to use
With oTask
    .ApplicationName = "myapp.exe"  '<- Replace with the name of your program
    With oTask.Triggers.Add
        .BeginDay = Date
        .StartTime = #8:00:00 AM#
        .Interval = 60  '<- Run every hour
        .Duration = 600 '<- for 10 hours
        .TriggerType = WeeklyTrigger
        .Weekly_DaysOfTheWeek = Monday + Tuesday + Wednesday + Thursday + Friday
    End With
End With

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
merowingerAuthor Commented:
this looks pretty good, but there comes an error:
line(4, 1) Microsoft VBScript runtime error: ActiveX component can't create object: 'TaskScheduler2.Schedule'
what to do???

what's the reason that you cannot use at command?
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

merowingerAuthor Commented:
i have to solve it without with at.  my employee said this!!!

Éric MoreauSenior .Net ConsultantCommented:
The reason to your error is that you need to download (and register it) the component from http://www.mvps.org/emorcillo/vb6/grl/index.shtml
merowingerAuthor Commented:
how can i install and register this???
merowingerAuthor Commented:
ok now i have registerd the dll succesfully but there anjway comes an error:
line(6, 1) Microsoft VBScript runtime error: Object required: '[undefined]'
merowingerAuthor Commented:
i found your error
you definied otask and used x

now it works

thanks a lot!!!!

David LeeCommented:

Sorry, about that.  My fingers and brain don't always work together like they should.
merowingerAuthor Commented:

one last question:
how can i make this part variable???
.StartTime = #08:00:00 AM#

for examble
mytime = 09:00:00
.StartTime = mytime

David LeeCommented:
Well, the simplest way is to just set StartTime directly.  Setting mytime to some value and then setting StartTime to the value of mytime doesn't gain anything.  If you want to change the start time, then

    .StartTime = #Whatever time you want#

The # signs around a time comprise a date litteral.  If instead you want to pass a time, then use the CDate() function.  For example:

    .StartTime = CDate("09:00:00")


    .StartTime = CDate(mytime)

assuming that mytime contains a valid time.
I was able to use this just fine to create a task but it will only run if I set my password on the task tab. Any way around this?
David LeeCommented:
Not that I know of.  Tasks have to run under some account, although not necessarily yours.  If the task is to run under your account, then you have to supply your password.  If you want to run it under some other account, then you'll have to supply the password for that account.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.