设置为无论用户是否登录都运行时,任务计划程序无法打开批处理文件 [英] Task scheduler cannot open batch file when set to run whether user is logged on or not

查看:762
本文介绍了设置为无论用户是否登录都运行时,任务计划程序无法打开批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统:Windows Server 2008 R2 Enterprise

OS: Windows Server 2008 R2 Enterprise

注销后,我无法使Task Scheduler运行.bat文件.我有一个要使用的生产.bat文件,但是出于故障排除的目的,我正在使用C:\ Users \ Administrator \ Desktop \ test.bat

I am unable to get the Task Scheduler to run .bat files while I am logged off. I have a a production .bat file I want to use, but for my troubleshooting purposes I am using C:\Users\Administrator\Desktop\test.bat

test.bat非常简单.它包含的所有内容是: taskkill/im notepad.exe

test.bat is very simple. All it contains is: taskkill /im notepad.exe

它可以独立成功运行.如果打开了记事本,然后双击test.bat,则cmd窗口将闪烁并且记事本消失. .bat文件不是问题.

It runs successfully on its own. If I have Notepad open and I double-click test.bat then the cmd window flashes and Notepad dies. The .bat file is not the problem.

我在任务计划程序中创建的任务是测试taskkill"(不带引号).我可以在Windows资源管理器中看到其位置:C:\ Windows \ System32 \ Tasks \ Test taskkill

The task I created in Task Scheduler is "Test taskkill" (without the quotes). I can see its location in Windows Explorer: C:\Windows\System32\Tasks\Test taskkill

如果将任务设置为仅在用户登录时才运行,则该任务将起作用.使用此设置,我可以右键单击它> run,然后得到与双击.bat文件相同的行为.这意味着任务配置正确.

If the task is set to run only when the user is logged on then the task works. With this setting, I can right-click on it > run and I get the same behavior as if I double-click the .bat file. That means the task is configured correctly.

如果我将其设置为无论用户是否登录都可以运行,则当我右键单击>运行时,什么都不会发生.据报道,该作业在历史记录中已成功运行,但记事本仍然存在.我知道我正在为要配置为运行任务的帐户使用正确的凭据.该帐户是本地管理员.

If I set it to run whether or not the user is logged on then when I right-click > run nothing obvious happens. The job is reported as having been run successfully in the history, but Notepad survives. I know that I am using the proper credentials for the account that I am configuring to run the task. That account is the local administrator.

此问题看起来与过去其他问题类似:

This issue appears similar to issues other have had in the past:

在计划任务中运行.bat文件

第二个链接中的线程似乎对许多人来说解决了一个相同的问题,建议用于运行任务的帐户需要对.bat文件以及.bat文件修改的所有文件的显式许可.这是非常有前途的(如果令人讨厌的要求).但是,我已经确认或将本地管理员的显式权限分配给以下区域,但是我仍然没有成功:

The thread in the second link seemed to resolve an identical issue for many people with the suggestion that the account used to run the task requires explicit permission to the .bat file and all files that the .bat file modifies. This was very promising (if an annoying requirement). However, I have confirmed or assigned explicit permissions for the local administrator to the following areas, and I am still not successful:

  • C:\ Users \ Administrator \ Desktop \
  • C:\ Users \ Administrator \ Desktop \ test.bat
  • C:\ Windows \ System32 \ Tasks \
  • C:\ Windows \ System32 \ Tasks \ Test taskkill

此外,我已经确认本地管理员帐户位于本地管理员组中.

Additionally, I have confirmed that the local administrator account is in the local administrators group.

我是否缺少其他需要设置的权限?还有其他我应该看的东西吗?谢谢!

Am I missing some other permissions that needs to be set? Is there something else I should be looking at? Thanks!

推荐答案

我在承包商的帮助下解决了这个问题,该承包商正在为我的机构做其他工作.

I have resolved this problem with help from a contractor who was doing some other work for my institution.

在任务的属性窗口中,在操作"选项卡上,当创建或编辑用于打开批处理文件的操作(在我的情况下为test.bat)时,存在"Program/script:"字段,并且还存在开始于(可选):"字段.我以前有"Program/script:"字段,其中包含文件的完整路径,以文件名结尾,而我的"Start in(可选):"字段为空.在任务的属性窗口的常规"选项卡中将任务设置为仅在用户登录时运行"时,此配置似乎可以正常工作.但是,当任务设置为无论用户是否登录都运行"时,此配置不起作用.

In the properties window for the task, on the Action tab, when creating or editing the action that opens the batch file (in my case test.bat), there is the "Program/script:" field and there is also a "Start in (optional):" field. I previously had the "Program/script:" field containing the full path to the file, ending with the file name, and I had the "Start in (optional):" field null. This configuration appears to work without issue when the task is set to "Run only when user is logged on" in the General tab of the task's properties window. However, this configuration does not work when the task is set to "Run whether user is logged on or not".

为了解决该问题,我更改了操作,以使"Program/script:"字段仅包含文件名,而不包含文件路径.我将文件路径放在开始于(可选):"字段中.当任务设置为仅在用户登录时运行"时,此配置有效!我已经测试了在触发器上运行的任务以及手动运行的任务.

In order to resolve the problem, I changed the action so that the "Program/script:" field contained only the file name, not the file path. I put the file path in the "Start in (optional):" field. This configuration works when the task is set to "Run only when user is logged on"! I have tested with the task running on a trigger and also with running it manually.

这篇关于设置为无论用户是否登录都运行时,任务计划程序无法打开批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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