Windows计划任务
我创建了一个 Windows 7 计划任务:
schtasks /create /tn MyTask /tr C:\temp\test\MyScript.bat /sc MINUTE
问题是该任务似乎由 Windows 执行,但我认为它找不到正在运行的 BAT 脚本。有一个快速闪烁窗口,但无法读取问题所在。
另一方面,如果我将脚本放在 Windows/System32 下,则一切正常。
schtasks /create /tn MyTask /tr C:\windows\system32\MyScript.bat /sc MINUTE
有人知道为什么第二个计划任务比第一个计划任务更有效吗?
这整个事情是从网页在 Windows 机器上安装程序的一部分。所以我想将 BAT 文件安装在正确的目录中,而不是 System32。
谢谢你的帮助。
I have created a Windows 7 scheduled task:
schtasks /create /tn MyTask /tr C:\temp\test\MyScript.bat /sc MINUTE
Problem is that this task seems to get executed by Windows but I think it can not find the running BAT script. There is a quick flash window but can't read what the problem is.
On the other hand, if I place the script under Windows/System32 everything works fine.
schtasks /create /tn MyTask /tr C:\windows\system32\MyScript.bat /sc MINUTE
Anyone knows why the second schedule task works compared to the first one?
This whole thing is part of installing a program on a windows machine from a web page. So I would like to have the BAT file installed in its correct directory and not the System32.
Thanks for you help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C:\temp
是一个临时目录,操作系统会定期清理。因此,您应该首先检查以确保批处理文件确实存在,然后考虑将其移动到更永久的位置。其次,您是否尝试过从预期位置手动运行任务?这应该可以帮助您了解输出是什么。您还可以将 PAUSE 添加到批处理文件的底部(按照评论者的建议),以确保它保持足够长的时间以便您看到输出。
一些可能的问题是:
%windir%
中的某些资源,当从其他位置运行批处理文件时,该资源将不起作用。C:\temp
is a temporary directory may be cleaned by the OS periodically. So you should first check to make sure that batch file is actually there, and then consider moving it to a more permanent location.Second, have you tried running the task manually from its intended location? That should help you see what the output is. You can also add PAUSE to the bottom of the batch file (as suggested by commenters) to ensure that it stays up long enough for you to see the output.
Some likely problems are:
%windir%
via a relative path, which won't work when the batch file is run from a different location.IIRC,schtasks 不加载用户配置文件:很可能没有设置您需要的变量。
尝试在命令行(/tr 之后)前面添加
cmd /K
。它将使控制台保持活动状态。华泰
IIRC, schtasks does not load user profile: Most probably a variable is not set that you need.
Try to prepend your command line (after /tr) with
cmd /K
. It will make the console kept alive.HTH