Running .vbs through task Scheduler

你离开我真会死。 提交于 2020-01-14 03:27:06

问题


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

Then the Action in Task Scheduler is:

Program/Script: "FilePath\CombinePDFS.vbs"

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.

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.


回答1:


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).

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.

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



来源:https://stackoverflow.com/questions/31193573/running-vbs-through-task-scheduler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!