[英]Windows Task Scheduler not running VBScript when set to “Run if logged on or not”
I'm trying to run a .vbs file as a scheduled task through Windows Task Scheduler. 我正在尝试通过Windows任务计划程序将.vbs文件作为计划任务运行。 Under the 'General' tab, when I select "Run only when user is logged on", the script executes as expected. 在“常规”选项卡下,当我选择“仅在用户登录时运行”时,脚本将按预期执行。
However, when I select "Run whether user is logged on or not", and enter the appropriate credentials, the task runs at the scheduled time, but the script does not actually run. 但是,当我选择“运行用户是否登录”并输入相应的凭据时,任务将在计划的时间运行,但脚本实际上并未运行。 I've already tried running the script under wscript.exe as well as cscript.exe, but no luck with either. 我已经尝试在wscript.exe下运行脚本以及cscript.exe,但两者都没有运气。
EDIT: Even if I am logged in when the task begins, the script will still not run under the "logged in or out" setting. 编辑:即使我在任务开始时登录,脚本仍然无法在“登录或退出”设置下运行。
Additional info: The purpose of this scheduled task is to run before I arrive at work. 附加信息:此计划任务的目的是在我到达工作岗位之前运行。 I've already configured my BIOS to startup at a predetermined time (06:00), and set the Task Scheduler to run at 06:27. 我已经将BIOS配置为在预定时间(06:00)启动,并将任务计划程序设置为在06:27运行。 I've successfully tested the BIOS startup, as well as the script itself (including using the Task Scheduler to run it). 我已经成功测试了BIOS启动以及脚本本身(包括使用Task Scheduler来运行它)。 Therefore, the only weak link I can find is the option to "Run whether the user is logged on or not". 因此,我能找到的唯一弱链接是“运行用户是否登录”选项。
I'm running Windows 7 Enterprise. 我正在运行Windows 7 Enterprise。
Any help would be appreciated! 任何帮助,将不胜感激!
This is because normally it would run the script using the shell handler, which by default is wscript.exe
. 这是因为通常它会使用shell处理程序运行脚本,该处理程序默认为wscript.exe
。 When there's no desktop environment (because no-one is logged-in) it would fail and abort script execution (or rather, not run the script in the first place). 如果没有桌面环境(因为没有人登录),它将失败并中止脚本执行(或者更确切地说,不首先运行脚本)。
To fix this, instead of running the .vbs file directly, change it to run cscript.exe
(the command-line script runtime program) with the script's filename passed as the first argument. 要解决此问题,请将其更改为运行cscript.exe
(命令行脚本运行时程序),而不是直接运行.vbs文件,并将脚本的文件名作为第一个参数传递。 Also be sure to ensure you don't have any InputBox
or MessageBox
calls (instead use WScript.Echo
to return messages to the user: wscript
displays message-boxes, but cscript
will write it to the console. 另外一定要确保没有任何InputBox
或MessageBox
调用(而是使用WScript.Echo
将消息返回给用户: wscript
显示消息框,但cscript
会将其写入控制台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.