Run scheduled task from VBScript

3.3k Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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