• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 867
  • Last Modified:

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!!!
mero
0
merowinger
Asked:
merowinger
1 Solution
 
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
    .Save
End With
0
 
merowingerAuthor Commented:
hi,
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???

mero
0
 
EDDYKTCommented:
what's the reason that you cannot use at command?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

mero
0
 
É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
0
 
merowingerAuthor Commented:
how can i install and register this???
0
 
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]'
0
 
merowingerAuthor Commented:
i found your error
you definied otask and used x

now it works

thanks a lot!!!!

mero
0
 
David LeeCommented:
mero,

Sorry, about that.  My fingers and brain don't always work together like they should.
0
 
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

mero
0
 
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")

or

    .StartTime = CDate(mytime)

assuming that mytime contains a valid time.
0
 
billymcquearyCommented:
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?
0
 
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now