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

Posted on 2005-04-22
Last Modified: 2012-08-13
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
Question by:billymcqueary
    1 Comment
    LVL 29

    Accepted Solution

    'You can use a command line to create,delete,start,stop..etc..a task
    'Just create a batch file


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now