Computing.Net > Forums > Programming > VBscrip Schedule Task

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBscrip Schedule Task

Reply to Message Icon

Name: AJ (by William Jimenez)
Date: October 22, 2008 at 10:45:52 Pacific
OS: XP
CPU/Ram: Dell
Comment:

Hello,

I have come across the code below to schedule a task via VBScript

It works great with a couple of exeptions.

a)Scheduled task is all greyed out and I'm unable to changed it via the task scheduler.

b)I need to add C:\BAK to the "Start in" field on the scheduled task.

Can these two things be added? Thank you in advance for your help. Code is below.

const MON = 1
const TUE = 2
const WED = 4
const THU = 8
const FRI = 16
const SAT = 32
const SUN = 64

' ------ SCRIPT CONFIGURATION ------
strComputer = "."
strCommand = "C:\BAK\BackupMyData.bat"
strStartTime = "********163000.000000-240" ' 14:30 EDT
'YYYYMMDDHHMMSS.MMMMMM-/+TZO
boolRepeat = TRUE ' Repeat the task periodically
intWeekDay = MON OR TUE OR WED OR THU OR FRI' Repeat task every Monday-Friday
intMonthDay = "" ' Set this if you want the task to repeat monthly
boolInteract = FALSE ' Do not interact with the desktop
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "")
set objNewTask = objWMI.Get("Win32_ScheduledJob")
intRC = objNewTask.Create(strCommand, _
strstartTime, _
boolRepeat, _
intWeekDay, _
intMonthDay, _
boolInteract, _
intJobID)
if intRC <> 0 then
Wscript.Echo "Error creating task: " & intRC
else
WScript.Echo "Successfully scheduled task."
end if



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 22, 2008 at 17:34:56 Pacific
Reply:

b)I need to add C:\BAK to the "Start in" field on the scheduled task.
The problem with WMI's Win32_ScheduledJob is that it creates an AT job, not a Scheduled Tasks job. This means there's no "start in" field to fill in. You're using a command script, though, so you should be able to modify that to change to whatever directory you choose.

a)Scheduled task is all greyed out and I'm unable to changed it via the task scheduler.
Go to your Run box and type:

cmd /c for %a in ("%systemroot%\tasks\at*") do schtasks /change /ru system /tn %~Na

That should make the jobs editable.

0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBscrip Schedule Task

batch file to set in schedule task www.computing.net/answers/programming/batch-file-to-set-in-schedule-task/14751.html

Batch file not run scheduled task www.computing.net/answers/programming/batch-file-not-run-scheduled-task/16757.html

Batch scripts/Scheduled Tasks www.computing.net/answers/programming/batch-scriptsscheduled-tasks/17448.html