Search code examples
windowsvbscriptschedulertaskscheduler

Run scheduled task from VBScript


How to run scheduled task inside .vbs script?

It's not about how to schedule .vbs script inside Task Scheduler.

But I have a task that I want to run by running this one .vbs script.


Solution

  • The simplest way is to shell out to the schtasks commandline utility.

    taskname = "something"
    Set sh = CreateObject("WScript.Shell")
    rc = sh.Run("schtasks /run /tn """ & taskname & """")
    

    You could also use the Task Scheduler scripting API, but that would require more code.

    taskname = "something"
    
    Set sched = CreateObject("Schedule.Service")
    sched.Connect()
    
    Set root = sched.GetFolder("\")
    Set task = root.GetTask(taskname)
    
    task.Run Null