Scheduling Task


D

dm4714

Can someone show me a script to setup scheduled tasks for W2K and XP
systems? I'd like to publish the scripts to multiple clients.

Thanks.
 
Ad

Advertisements

S

Scott McNairy \(MVP\)

The Win32_scheduledJob class uses the same interface as at.exe so the
resulting processes use the local system context to run under.

set svc = GetObject("winmgmts:root\cimv2")
set obj = svc.get("Win32_ScheduledJob")

Set objMethod = obj.Methods_("Create")
Set objInParam = objMethod.inParameters.SpawnInstance_()

objInParam.RunRepeatedly = True
objInParam.Command = "calc.exe"
objInParam.InteractWithDesktop = true ' default is false
objInParam.StartTime = "********032200.000000-300" ' these stars must be
here according to the description on this input param
objInParam.DaysOfWeek = 64 ' this is a bit value see the docs on msdn to see
what they mean

Set objOutParam = obj.ExecMethod_("Create", ObjInParam)

if err = 0 then
if objOutParams.ReturnValue <> 0 then
wscript.echo "Method was called successfully but failed with code "
& objOutParams.ReturnValue
else
wscript.echo "Created the job"
end if
else
wscript.echo "Error: " & err.description
end if
 
D

dm4714

I've noticed that if I use the script to create a task.... it cannot be
edited from Explore | Scheduled Tasks. Everything is ghosted out. I'm
using WinXP Pro.

Any idea why?
 
Ad

Advertisements

S

Scott McNairy \(MVP\)

Yes, they are using a different interface set and are not compatible. The
At.exe interfaces are different from those of the scheduled tasks UI.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top