• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

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
1 Solution
'You can use a command line to create,delete,start,stop..etc..a task
'Just create a batch file



Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now