Windows计划任务

发布于 2024-09-01 09:46:07 字数 472 浏览 8 评论 0原文

我创建了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨的味道风的声音 2024-09-08 09:46:07

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:

  • You're using some resource which is in %windir% via a relative path, which won't work when the batch file is run from a different location.
  • The scheduled task is running as a different user and doesn't have the proper permissions.
  • The task is doing something that requires elevation, but the task itself is not set to run elevated.
痴骨ら 2024-09-08 09:46:07

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文