为什么我的任务计划更新其“上次运行时间”正确,并给予'(为0x0)'的'最后运行结果“,但仍然没有实际工作? [英] Why is my Scheduled Task updating its 'Last Run Time' correctly, and giving a 'Last Run Result' of '(0x0)', but still not actually working?

查看:3281
本文介绍了为什么我的任务计划更新其“上次运行时间”正确,并给予'(为0x0)'的'最后运行结果“,但仍然没有实际工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个被设置为Windows Server 2012中的一个计划任务运行的批处理文件。

I have a batch file which is set to run as a Scheduled Task on Windows Server 2012.

当我运行命令行手工批处理文件,它的工作原理。当我在我的任务计划任务右键单击并手工运行它,它仍然能正常工作。

When I run the batch file by hand from the command line, it works. When I right-click on my task in Task Scheduler and manually run it, it still works fine.

但是,如果我就照为它设置的计划任务运行...那么它似乎有时工作,而不是其他。

But, if I let the task run according to the schedule set for it... then it seems to work sometimes, but not others.

我已经设置为给定用户运行的任务;我已经设置了目录中启动正确;我试图给它最高权限。这些都不利于

I have already set the task to run as a given user; I have set its 'Start in' directory correctly; I have tried giving it highest privileges. None of that helps.

推荐答案

摘要:

Summary:

当您在Windows Server 2012上运行的批处理文件作为预定任务,它只能看到共享的环境变量。它的的看到你已经将它设置为运行用户的用户特定的环境变量。

When you are running a batch file as a Scheduled Task on Windows Server 2012, it only sees shared environment variables. It does not see the user specific environment variables for the user you have set it to run as.

不过 - 这使问题变得更加困难调试 - 如果你碰巧的身份登录该任务将运行用户,那么任务确实看到你所期望的环境变量和工作正常(这适用无论是使用右键/在任务计划程序运行运行或运行在触发)。

However - and this makes the problem a lot harder to debug - if you happen to be logged in as the user which the task will run as, then the task does see the environment variables which you would expect, and works fine (this applies whether it is run using right-click/Run in the Task Scheduler, or runs on a trigger).

详细资料:

More Detail:

运行集>的test.txt 它自己的,在一个批处理文件,在测试计划的任务,就是看这个事情最简单的方法! (你必须让它在触发运行,而你还没有登录,真正看到这个问题。)

Running SET>test.txt on it's own, in a batch file, in a test scheduled task, is the easiest way to see this going on! (You must let it run on a trigger while you are not logged in, to actually see the problem.)

必须有一个以上的答案为标题的问题,但上面的总结出这个问题这是发生在我身上,这把我的年龄的调试版本的解释。我相信这是在Windows如何二千零十二分之七把手计划任务的bug。

There must be more than one answer to the headline question, but the summary above gives the explanation for the version of this problem which was happening to me, which took me ages to debug. I believe it is bug in how Windows 7 / 2012 handles scheduled tasks.

在我的情况下,这些意外的环境设置都导致一个给定的系统命令(actaully, WMIC )不是路径上是可见的(这也是因为我的路径变量没有正确配置,因为我觉得 WMIC 应该是在默认共享值 PATH ,但那是另一回事...),从而无法运行的批处理文件的其余部分,因此很多地方都没有;但整体批处理文件仍给予零返回code。

In my case, these unexpected environment settings were leading to a given system command (actaully, wmic) not being visible on the path (which was also because my path variables were not correctly configured, since I think wmic should be in the default shared value for PATH, but that is another story...), hence failing to run, hence many parts of the rest of the batch file were failing; but the overall batch file was still giving a return code of zero.

计划任务特别硬的(不是不可能,只是...硬)调试,特别是如果所有的文本输出这显示错误将会标准错误而不是标准输出(因为它是,举例来说,如果一个给定的命令不能在所有发现的)。

Scheduled tasks are particularly hard (not impossible, just ... hard) to debug, especially if all of the text output which would indicate the error is going to stderr rather than stdout (as it is, for instance, if a given command cannot be found at all).

更新:从更详细的测试,似乎 USERDNSDOMAIN,
USERDOMAIN USERNAME 获得正确设置; USERPROFILE 设置(错误地)为Windows默认用户的值(即 C:\\用户\\默认);和其他一切设置(错误地)设定的唯一共享的环境变量(这是不是指定用户的正确设置,甚至不会为Windows默认用户正确的设置,这应该从获取其用户特定的环境变量 HKEY_USERS \\ .DEFAULT \\环境)。

UPDATE: From more detailed testing, it seems that USERDNSDOMAIN, USERDOMAIN and USERNAME get set correctly; USERPROFILE is set (incorrectly) to the value for the Windows default user (i.e. C:\Users\Default); and everything else is set (incorrectly) to the set of shared environment variables only (which is not the correct set for the specified user, and not even the correct set for the Windows default user, which should get its user specific environment variables from HKEY_USERS\.Default\Environment).

PS:这是不一样的问题,因为 Windows 7的任务调度器不使用更新的路径,实际上更改任何共享的环境变量,包括 PATH ,确实会看到马上(对我做了测试,在Windows 2012 R2),没有重新启动的任何进程。

PS: This is not the same issue as windows 7 task scheduler doesn't use updated path , and in fact changes to any shared environment variables, including PATH, do get seen straight away (on the tests I did, on Windows 2012 R2), with no restart of any process.

这篇关于为什么我的任务计划更新其“上次运行时间”正确,并给予'(为0x0)'的'最后运行结果“,但仍然没有实际工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆