Link to home
Start Free TrialLog in
Avatar of billymcqueary
billymcqueary

asked on

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"
Else
      Wscript.Echo "Task created: " & JobID
End If
wscript.quit
ASKER CERTIFIED SOLUTION
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial