以编程方式在Windows中创建计划任务 - 0x8004130f错误

17 scheduled-tasks

我在运行计划任务时遇到了重大问题.使用Microsoft提供的ITaskScheduler接口可以很好地创建任务.该任务设置为仅在用户登录时运行.

问题是该任务没有运行,日志文件SchedLgU.txt引用的原因是:

"The attempt to retrieve account information for the specified task failed; therefore, the task did not run. Either an error occurred, or no account information existed for the task.

The specific error is:

0x8004130f: No account information could be found in the Task Scheduler security database for the task indicated."
Run Code Online (Sandbox Code Playgroud)

我知道可以创建一个没有帐户信息的计划任务,因为Google Updater计划任务执行此操作,并且运行正常.

我可以从网络搜索中收集到的是,Windows有一个"计划任务数据库",需要为每个任务提供凭据信息才能运行.

有谁知道如何修改此凭据数据库或任何其他方式来运行我的任务?

Dav*_*ass 24

GoogleUpdateTaskMachine任务使用"NT AUTHORITY\SYSTEM"来运行任务.您可以使用schtasks命令和带有"System"或""作为参数的/ ru开关来完成此操作.像这样:

schtasks /create /tn "My App" /tr c:\apps\myapp.exe /sc monthly /d 15 /ru "System"
Run Code Online (Sandbox Code Playgroud)

它不会提示输入密码.

有关详细信息,请参阅technet.

  • 为什么这被否决?我把它投了回来. (3认同)

Ger*_*son 9

你可以使用批处理脚本.

schtasks /create /tn UNO /tr YOURAPP.EXE /sc HOURLY /mo 2
Run Code Online (Sandbox Code Playgroud)

你去吧

阅读:如何使用Schtasks.exe在Windows Server 2003中安排任务


Ste*_*tin 2

据我所知,并且文档支持了这一点,计划任务需要一个帐户。如果您将任务设置为仅在用户登录时运行,这仅意味着不需要密码,您仍然需要一个帐户。可以将该帐户设置为一个组,这样只要该组中的任何人登录,该任务就会在触发时运行。例如,您可以将帐户设置为“用户”,以便任何人登录时都可以运行任务。