Windows 任务计划程序不运行 VBScript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29663480/
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
Windows Task Scheduler Doesn't Run VBScript
提问by lovechillcool
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.
我正在尝试使用 Windows 任务计划程序自动执行 VBScript。但是,我尝试使用cscript.exe
+"C:\...\script.vbs"
但它没有运行。我还尝试在 CMD ( cscript.exe "C:\...\script.vbs"
) 中直接运行相同的命令并且它起作用了。
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.
我只是尝试将设置切换为"Run only when user is logged on"
from"Run whether user is logged on or not"
并且它起作用了。我想知道是否有办法让我的任务即使在用户注销时也能运行。
采纳答案by lovechillcool
After hours of research, one of Blake Morrison (from Microsoft)'s blogs came up; it mentioned that
经过数小时的研究,Blake Morrison(来自微软)的博客之一出现了;它提到
If running a .vbs / .ps1 script, try launching it from a .cmd / .bat script
如果运行 .vbs / .ps1 脚本,请尝试从 .cmd / .bat 脚本启动它
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.
因此,请创建一个调用您的 VBScript 的 .cmd/.bat 文件。例如:cscript.exe YourScript.vbs
将在您的 .cmd/.bat 脚本中。
回答by Jen R
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!"
然后调度批处理文件而不是 vbs。这将允许您查看阻止它运行的情况。您在控制台 (CMD) 中看到的任何错误都将输出到“Started!”之间的日志文件中。和“停止!”
回答by ZygD
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:
有什么好烦的?我不使用 .cmd/.bat 并且脚本有效!(此处
为Windows7)我的 VBS 脚本(作为计划任务)在以下 4 种情况下的任何情况下都运行良好:
- cscript and option "Run only when user is logged on"
- cscript and option "Run whether user is logged on or not"
- wscript and option "Run only when user is logged on"
- wscript and option "Run whether user is logged on or not"
- c脚本和选项“仅在用户登录时运行”
- c脚本和选项“无论用户是否登录都运行”
- w脚本和选项“仅在用户登录时运行”
- w脚本和选项“无论用户是否登录都运行”
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)
回答by Trigger
The .vbs file is running invisibly, which is a consequence of running it with the 'logged on or not' option.
.vbs 文件在不可见的情况下运行,这是使用“登录与否”选项运行它的结果。
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 notrun interactively.
To make a task run interactively, select the Run only when user is logged on radio button.
您可以指定即使在触发任务时计划运行任务的帐户未登录时也应运行任务。
为此,请选择标有“运行”的单选按钮,无论用户是否登录。
如果选中此单选按钮,则任务将不会以交互方式运行。
要使任务以交互方式运行,请选择仅在用户登录时运行单选按钮。
回答by Ste
You can do this.
你可以这样做。
cmd
as the Program./c start cscript //nologo "W:\Pathto with spaces\VBScript.vbs"
回答by Markus
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 newplanned task with all settings copied from the original one.
曾不止一次经历过,按计划运行的 VBScript 任务可以正常运行数月和数年,但尽管没有任何更改,但突然不再起作用。尝试使用此处和其他地方给出的所有配方来响应任务,但没有成功。我的解决方法是创建一个新的计划任务,并从原始任务复制所有设置。
回答by Curtis
Greg answered this https://superuser.com/a/816073
格雷格回答了这个https://superuser.com/a/816073
Basically you need to create 2 folders:
基本上你需要创建2个文件夹:
You have to create a folder (or two on a 64bit-windows):
您必须创建一个文件夹(或在 64 位 Windows 上创建两个):
(32Bit, always) C:\Windows\System32\config\systemprofile\Desktop
(32 位,始终)C:\Windows\System32\config\systemprofile\Desktop
(64Bit) C:\Windows\SysWOW64\config\systemprofile\Desktop
(64 位) C:\Windows\SysWOW64\config\systemprofile\Desktop
Fixed the issue for me (and I could point to the .vbs file, not bat needed).
为我解决了这个问题(我可以指向 .vbs 文件,不需要 bat)。