adding a task to scheduled tasks with a .vbs logon script that calls another .vbs file locally

This is the code I'm using now to test adding a scheduled task to a users system. I tested it by running the script manually to add it to schedule tasks and also adding it to their logon script. Both seem to give me the same result, at the scheduled time it says that it runs but nothing happens. When I manually execute the outlookpstbackup.vbs file it works fine. Also all the options on the task are greyed out if that makes a difference. Any ideas?

Option Explicit
Dim oShell, currentOS
Set oShell = CreateObject("WScript.Shell")
Dim objService, objNewJob, JobID, errJobCreated, objShell, objFolder, objFolderItem, strComputer, objWMIService, colDisks, objDisk, defragHour
Const system32_folder = &H25&
set objShell = CreateObject("Shell.Application")
set objFolder = objShell.Namespace(system32_folder)
Set objFolderItem = objFolder.Self
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create("c:\outlookpstbackup.vbs", "********064500.000000-360", True, 1 or 2 or 4 or 8 or 16, , , JobID)
If errJobCreated <> 0 Then
      Wscript.Echo "Error on task creation"
      Wscript.Echo "Task created: " & JobID
End If
Who is Participating?
nffvrxqgrcfqvvcConnect With a Mentor Commented:
'You can use a command line to create,delete,start,stop..etc..a task
'Just create a batch file

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.

All Courses

From novice to tech pro — start learning today.