简体   繁体   English

从VBScript运行计划的任务

[英]Run scheduled task from VBScript

How to run scheduled task inside .vbs script? 如何在.vbs脚本中运行计划任务?

It's not about how to schedule .vbs script inside Task Scheduler. 这与如何在Task Scheduler中计划.vbs脚本无关。

But I have a task that I want to run by running this one .vbs script. 但是我有一个想通过运行此.vbs脚本来运行的任务。

The simplest way is to shell out to the schtasks commandline utility. 最简单的方法是使用schtasks命令行实用程序。

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. 您也可以使用Task Scheduler脚本API ,但这将需要更多代码。

taskname = "something"

Set sched = CreateObject("Schedule.Service")
sched.Connect()

Set root = sched.GetFolder("\")
Set task = root.GetTask(taskname)

task.Run Null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM