windows 使用 vbscript 检查计划任务是否正在运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8013495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:23:56  来源:igfitidea点击:

Check if a scheduled task is running using vbscript

windowsscriptingvbscript

提问by JoeOD

Is it possible to determine if a scheduled task is running on a local or remote machine using vbscript?

是否可以使用 vbscript 确定计划任务是在本地还是远程计算机上运行?

回答by Hans Olsson

There's a WMI class called Win32_ScheduledJobthat has some status fields that might be useful. Especially the ElapsedTimefield looks like it might be what you're looking for, assuming that it gets reset when the task stops.
Here'ssome sample code for looking at the statuses. Just set strComputerto the name of the computer you want to look at (.means the local computer).

有一个名为Win32_ScheduledJob的 WMI 类,其中包含一些可能有用的状态字段。特别是该ElapsedTime字段看起来可能就是您要查找的内容,假设它在任务停止时被重置。
下面是一些用于查看状态的示例代码。只需设置strComputer为您要查看的计算机的名称(.表示本地计算机)。

Otherwise, if that doesn't work, you might be able to just look at the Schedlgu.txtfile in the Windowsdirectory and see if it's started but not yet stopped.

否则,如果这不起作用,您可以查看目录Schedlgu.txt中的Windows文件,看看它是否已启动但尚未停止。

回答by ewall

You might be able to get this information with the command-line command schtasks /query... but you'd probably have to grep the output to find only the jobs with a status of "Running".

您可能可以使用命令行命令获取此信息schtasks /query……但您可能必须对输出进行 grep 以仅查找状态为“正在运行”的作业。

Details on usage can be found here.

可以在此处找到有关使用的详细信息。