通过任务计划程序运行 .vbs [英] Running .vbs through task Scheduler

查看:89
本文介绍了通过任务计划程序运行 .vbs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过任务计划程序运行 vbs 脚本.vbs 脚本的代码是

I am trying to run a vbs script through Task Scheduler. The code for the vbs script is

Dim ObjExcel, ObjWB
Set ObjExcel = CreateObject("excel.application")
'vbs opens a file specified by the path below
Set ObjWB = ObjExcel.Workbooks.Open("FilePath\CombinePDFs.xlsm")
'either use the Workbook Open event (if macros are enabled), or Application.Run

ObjWB.Close False
ObjExcel.Quit
Set ObjExcel = Nothing

那么Task Scheduler中的Action为:

Then the Action in Task Scheduler is:

Program/Script: "FilePath\CombinePDFS.vbs"

没有添加参数或开始".到目前为止,尝试运行它已经导致它运行了 20 分钟,而且看起来它永远不会停止.运行通常需要 1 分钟.

With no added argument or "Start in." Trying to run this had caused it to run 20 minutes so far and it doesn't look like it's ever going to stop. It usually takes 1 minute to run.

我在网上读到有人说我需要在 Cscript 中执行它,但是我没有完成任何命令编码,所以我无法弄清楚 CScript.exe 文件应该放在编辑操作"中的哪个位置"盒子.关于我需要将 Cscript.exe 放在哪里的任何说明都将是最有帮助的,或者如果您看到另一个问题,请告诉我.

I've read online that people say I need to be executing this in Cscript, but I have done no command coding and so I can't figure out where the CScript.exe file is supposed to go in the "Edit Action" box. Any clarification on where I need to put the Cscript.exe would be most helpful, or if you see another problem let me know.

推荐答案

在任务计划程序中只使用脚本名称作为操作"是可以的.Windows 将执行它,就像您双击它一样,它将使用 vbs 扩展(通常是 wscript.exe)的默认应用程序处理程序运行.

It's fine to use just the script name as the "Action" in Task Scheduler. Windows will execute it just as if you double-clicked it and it will run using the default app handler for the vbs extension (usually wscript.exe).

由于您正在运行交互式进程(启动 Excel),您必须在任务属性的 General 页面上选择 仅在用户登录时运行.即使您为任务指定了某些凭据,也无法在没有登录用户的情况下启动交互式进程.

Since you're running an interactive process (launching Excel), you must have Run only when user is logged in selected on the General page of the task properties. Interactive processes cannot be launched without a logged-on user, even if you specify certain credentials for the task.

这是 Windows Vista 中引入的新 Session 0 Isolation" 的一部分.有关详细信息,请参阅以下文章:

This is part of the new "Session 0 Isolation" introduced in Windows Vista. See the following article for more info:

http://blogs.technet.com/b/askperf/archive/2015/02/18/help-my-scheduled-task-does-not-run.aspx

这篇关于通过任务计划程序运行 .vbs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆