Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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.

![]() |
![]() |
![]() |

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