1
votes

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
Which version of Windows?Bond
Windows 7, sorry should have put that in. I'll add nowhypetech
Do you have Run only when user is logged in selected on the General page of the task properties.Bond
No it's Run whether user is logged on or not because I'll need it to run when my computer is logged off at night. It's also set to run with highest privileges.hypetech

1 Answers

1
votes

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