Windows Task Scheduler Doesn't Run VBScript

泄露秘密 提交于 2019-12-22 04:56:06

问题


I am trying to automate a VBScript by using Windows Task Scheduler. However, I tried to use cscript.exe + "C:\...\script.vbs" but it didn't run. I also tried to directly run the same command in CMD (cscript.exe "C:\...\script.vbs") and it worked.

What might be the problem?

EDIT :

I just tried to switch the setting to "Run only when user is logged on" from "Run whether user is logged on or not" and it worked. I am wondering if there is a way to make my task scheduled run even when the user is logged off.


回答1:


After hours of research, one of Blake Morrison (from Microsoft)'s blogs came up; it mentioned that

If running a .vbs / .ps1 script, try launching it from a .cmd / .bat script

see Help! My Scheduled Task does not run…

That blog also explains a lot of rules/tips when using Task Scheduler.

So please create a .cmd/.bat file that calls for your VBScript. For example: cscript.exe YourScript.vbs would be in your .cmd/.bat script.




回答2:


Write a batch file like this:

echo "Started!" > c:\foldergoeshere\log.txt
cscript.exe "C:\...\script.vbs" > c:\foldergoeshere\log.txt
echo "Stopped!" > c:\foldergoeshere\log.txt

Then schedule the batch file instead of the vbs. That will allow you to see what is happening that is preventing it from running. Any error that you would have seen executing in the console (CMD), will be instead output to that log file between "Started!" and "Stopped!"




回答3:


What's the hassle all about? I don't use .cmd/.bat and script works! (Windows7 here)
My VBS script (as a scheduled task) runs well on any scenario of these 4:

  1. cscript and option "Run only when user is logged on"
  2. cscript and option "Run whether user is logged on or not"
  3. wscript and option "Run only when user is logged on"
  4. wscript and option "Run whether user is logged on or not"

It's only that on the 1st scenario I encounter the black command window flashing on my screen.

Action settings:


or

My script, which simply creates a file:

Set objFSO = CreateObject("Scripting.FileSystemObject")
filename = "C:\Temp\" & Hour(Time) & Minute(Time) & Second(Time)
Set objFile = objFSO.CreateTextFile(filename)



回答4:


The .vbs file is running invisibly, which is a consequence of running it with the 'logged on or not' option.

You will not be allowed to interfere with a user using the computer, which means you will be able to help yourself, but not others.

Please read the following text from the Task Scheduler Help menu:

Task Security Context

You can specify that a task should run even if the account under which the task is scheduled to run is not logged on when the task is triggered.

To do this, select the radio button labeled Run whether user is logged on or not.

If this radio button is selected, tasks will not run interactively.

To make a task run interactively, select the Run only when user is logged on radio button.




回答5:


Have experienced more than once that a VBScript running as planned task worked fine for months and years but suddenly would not work any more despite nothing was changed. Have tried to reactive the task using all the recipes given here and elsewhere, but no success. My workaround was to create a new planned task with all settings copied from the original one.




回答6:


Greg answered this https://superuser.com/a/816073

Basically you need to create 2 folders:

You have to create a folder (or two on a 64bit-windows):

(32Bit, always) C:\Windows\System32\config\systemprofile\Desktop

(64Bit) C:\Windows\SysWOW64\config\systemprofile\Desktop

Fixed the issue for me (and I could point to the .vbs file, not bat needed).



来源:https://stackoverflow.com/questions/29663480/windows-task-scheduler-doesnt-run-vbscript

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