如何解决 Windows 计划任务未运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/865653/
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
How to troubleshoot Windows Scheduled Task not running?
提问by David Korn
In the process of deploying our .net app, I've got about 20 scheduled tasks set up on a server, all of which basically do the same thing: invoke a small .net console app that pulls data from a SQL db and posts it to a web service. Each task invokes a separate copy of the app, each copy having a different lookup ID value in its config file.
在部署我们的 .net 应用程序的过程中,我在服务器上设置了大约 20 个计划任务,所有这些任务基本上都做同样的事情:调用一个小的 .net 控制台应用程序,从 SQL 数据库中提取数据并将其发布到网络服务。每个任务调用应用程序的一个单独副本,每个副本在其配置文件中具有不同的查找 ID 值。
All but two of these tasks run reliably every night. Two of the tasks seem to sporadically stop running from time to time, and it's currently a mystery as to why. When they stop running, the scheduled task interface correctly shows their last run date, which is a day or more behind the other tasks, which have continued to run at the scheduled time. The tasks which stopped running do not run again on their own, despite being indicated as scheduled to run every night. There are no errors recorded in the event log or in the scheduled task interface itself. And here's the strangest part to us: If I manually kick off the scheduled task, it runs fine, it invokes the .net console app and everything finishes without anomaly. And then it continues to run fine at its scheduled time, for days or weeks at a time, only to eventually fail, seemingly out of the blue. It appears both tasks always start to fail on the same night.
除了其中两项任务之外,所有任务每晚都可靠地运行。其中两个任务似乎不时偶尔停止运行,目前尚不清楚原因。当他们停止运行时,计划任务界面会正确显示他们上次运行的日期,该日期比其他在计划时间继续运行的任务晚了一天或更长时间。停止运行的任务不会自行再次运行,尽管被指示按计划每晚运行。事件日志或计划任务界面本身没有记录错误。对我们来说最奇怪的部分是:如果我手动启动计划任务,它运行良好,它调用 .net 控制台应用程序并且一切都没有异常地完成。然后它继续在预定时间正常运行,一次运行数天或数周,但最终失败,似乎出乎意料。看来这两项任务总是在同一晚开始失败。
采纳答案by scottm
There's a "Last Result" column that should give you a code related to the task itself running (it's not going to have any kind of exception data). 0 means the task completed without errors. Anything else you can look up and see why the task won't start. If the task still seems to not be running, but you still see a 0 for the Last Result, that means there's something broken in your code, but it's exiting gracefully.
有一个“最后结果”列应该为您提供与正在运行的任务本身相关的代码(它不会有任何类型的异常数据)。0 表示任务完成且没有错误。您可以查找其他任何内容,看看为什么任务无法启动。如果任务似乎仍未运行,但您仍然看到 Last Result 为 0,这意味着您的代码中存在某些问题,但它正在正常退出。
回答by user2781523
Taskscheduler assumes on 64 bits systems that the applicaiton is 64 bit. If it is 32 bit launch it from the 32 bit command line, i.e. if you want to run c:\program files (x86)\Myprogram\Program.exe, tell taskscheduler to launch:
Taskscheduler 假设在 64 位系统上应用程序是 64 位。如果是 32 位从 32 位命令行启动它,即如果你想运行 c:\program files (x86)\Myprogram\Program.exe,告诉 taskscheduler 启动:
- %systemroot%\Syswow64\cmd.exe /C "c:\program files (x86)\Myprogram\Program.exe"
- %systemroot%\Syswow64\cmd.exe /C "c:\program files (x86)\Myprogram\Program.exe"
This forces it to launch from the 32 bit command-prompt and hence with 32 bit emulation.
这迫使它从 32 位命令提示符启动,因此使用 32 位仿真。
回答by dar0x
Did you set "Start in" property?
您是否设置了“开始于”属性?
If these .NET console apps need app.config or some files located into their path, you have to set "Start in" property to "c:\your\app\path\, otherwise they start as if they are in the system directory, and they cannot find files they need!
如果这些 .NET 控制台应用程序需要 app.config 或位于其路径中的某些文件,则必须将“Start in”属性设置为“c:\your\app\path\”,否则它们就像在系统目录中一样启动,他们找不到他们需要的文件!
回答by MikeBeaton
The answer to the below SO question may also be highly relevant to people reading this question (but, NB, it describes only onepossible specific problem with Scheduled Tasks and I believe neither of these questions is a duplicate of the other):
以下 SO 问题的答案也可能与阅读此问题的人高度相关(但是,注意,它仅描述了计划任务的一个可能的特定问题,我相信这些问题都不是另一个问题的重复):
为什么我的计划任务正确更新了它的“上次运行时间”,并给出了“(0x0)”的“上次运行结果”,但仍然没有实际工作?
The summary of the answer given to that other question is that Windows 2012 Scheduled Tasks do not see the correct environment variables, including PATH, for the account which the task is set to run as.
对另一个问题的回答总结是,Windows 2012 计划任务没有看到正确的环境变量,包括 PATH,对于设置为运行任务的帐户。
In terms of more general Scheduled Task troubleshooting (as asked about in this question), you can test for this particular issue (e.g. running SET > test.txt
in the task, as suggested in that answer), and once you can see it happening, you can work around it if it is affecting you.
就更一般的计划任务故障排除(如本问题中所问)而言,您可以测试此特定问题(例如SET > test.txt
在任务中运行,如该答案中所建议的那样),一旦您看到它发生,您就可以解决如果它影响到你。
回答by Justin
In my case, the scheduled task wouldn't run even though it said last run was successful (0). It turned out to be that the windows user account that was running the jobs had become locked out. I only realized this because I tried editing the existing scheduled task, set the user account to the same one, then hit OK and it gave me an error about the account being locked out.
就我而言,即使计划任务说上次运行成功 (0),它也不会运行。结果是运行作业的 Windows 用户帐户已被锁定。我之所以意识到这一点,是因为我尝试编辑现有的计划任务,将用户帐户设置为相同的帐户,然后点击“确定”,它给了我一个关于帐户被锁定的错误。
回答by Pranav Singh
I found this super helpful link:https://windowsreport.com/windows-scheduled-tasks-not-running/for thorough debugging steps for many use cases.
我发现了这个超级有用的链接:https: //windowsreport.com/windows-scheduled-tasks-not-running/用于许多用例的彻底调试步骤。
In my case user account with which scheduler was configured to run was locked that stopped execution of scheduled tasks without any logs or reporting problem.
在我的情况下,调度程序配置为运行的用户帐户被锁定,停止执行计划任务,没有任何日志或报告问题。
回答by Ian Mackinnon
One reason for Scheduled Tasks not running occurs when associating them with a password-less Windows user account: by default Scheduled Tasks are prevented from running with a blank password. If you want to run a Scheduled Task from an account with no password you have to disable a system variable:
将计划任务与无密码的 Windows 用户帐户相关联时,会出现计划任务未运行的原因之一:默认情况下,计划任务被阻止使用空白密码运行。如果要从没有密码的帐户运行计划任务,则必须禁用系统变量:
- Go to: Start > Administrative Tools > Local Security Policy > Security Settings > Local Policies > Security Options
- Select: "Accounts: Limit local account use of blank passwords to console logon only"
- Disable this variable
- 转到:开始 > 管理工具 > 本地安全策略 > 安全设置 > 本地策略 > 安全选项
- 选择:“帐户:将本地帐户使用空白密码限制为仅控制台登录”
- 禁用此变量
Disclaimer: It′s not recommended to have accounts with no password.
免责声明:不建议使用没有密码的帐户。
回答by gkrogers
I found this page helpful when I was trying to trouble-shoot a misbehaving Scheduled Task:
http://support.microsoft.com/kb/308558
当我尝试对行为不当的计划任务进行故障排除时,我发现此页面很有帮助:http:
//support.microsoft.com/kb/308558
Select View->Details to show the additional information, like Last Run Time, and Status, and this page gave me the meaning of the status/error code:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx
选择“查看”->“详细信息”以显示附加信息,例如上次运行时间和状态,此页面为我提供了状态/错误代码的含义:http:
//msdn.microsoft.com/en-us/library/windows /desktop/ms681381(v=vs.85).aspx
回答by Christian
Maybe they hung and were still running?
也许他们挂了,还在跑?
You can click on the extras-menu and choose the menu entry to view the log, then notepad will open a log file from the task planner
你可以点击 extras-menu 并选择菜单项查看日志,然后记事本会从任务计划器中打开一个日志文件