简体   繁体   English

如何在以本地管理员身份运行的命令行上创建计划任务以运行以不同用户身份运行的任务?

[英]How do I create a scheduled task on the command line that runs as local administrator to run a task that runs as a different user?

I need to create a scheduled task on the command line that runs a script as local administrator.我需要在以本地管理员身份运行脚本的命令行上创建计划任务。 One thing that this script does is run an installer as a specific domain user (that is already local admin on this machine).这个脚本做的一件事是作为特定的域用户(已经是这台机器上的本地管理员)运行安装程序。 This scheduled task needs to be run on startup, without requiring the user to log on.此计划任务需要在启动时运行,无需用户登录。 Note this is on Windows Server 2012.请注意,这是在 Windows Server 2012 上。

The problem is that using "schtasks /create /RU administrator /RP " to do so does not work as expected.问题是使用“schtasks /create /RU administrator /RP ”这样做并没有按预期工作。

It creates the scheduled task as expected, but when it runs the scheduled task it fails to run the installer as the domain user, and logs in the eventvwr system log " Application Error: The application was unable to start correctly (0xc0000142). Click OK to close the application. ".它按预期创建计划任务,但是当它运行计划任务时它无法以域用户身份运行安装程序,并在 eventvwr 系统日志中记录“应用程序错误:应用程序无法正确启动(0xc0000142)。单击确定关闭应用程序。”。

I can recreate the problem by making a scheduled task on the command line with "/RU administrator /RP " that runs a Powershell script, which starts notepad with different credentials.我可以通过使用运行 Powershell 脚本的“/RU administrator /RP”在命令行上创建计划任务来重现该问题,该脚本使用不同的凭据启动记事本。

This fails.这失败了。 But if I create the scheduled task without specifying "/RU administrator" it works (if I run cmd.exe as local administrator).但是,如果我在不指定“/RU 管理员”的情况下创建计划任务,它就可以工作(如果我以本地管理员身份运行 cmd.exe)。

However this won't work for me as if you don't specify a user with "/RU" then you cannot set the scheduled task to "run whether user is logged in or not".但是,这对我不起作用,因为如果您没有使用“/RU”指定用户,那么您就无法将计划任务设置为“无论用户是否登录都运行”。

There seems to be a fundamental difference when creating a scheduled task using schtasks between "/RU administrator" vs not passing "RU" but running cmd.exe as administrator.在“/RU 管理员”与不传递“RU”但以管理员身份运行 cmd.exe 之间使用 schtasks 创建计划任务时似乎存在根本区别。

Any way around this?有办法解决这个问题吗?

Try adding /RL Highest That worked for me尝试添加 /RL Highest 这对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有FTP的批处理文件从命令行运行,但不作为计划任务运行 - Batch file with FTP runs from command line, but not as scheduled task 使用命令行创建在特定用户登录名上运行的计划任务 - Create a scheduled task that runs on particular user login using commandline 如何以管理员身份在rake任务中运行shell命令? - How do I run a shell command inside a rake task as administrator? 如何通过命令行创建计划任务,其中包括高级选项 - How do I create a scheduled task, via command line, which includes advanced options 创建一个每分钟运行一次的计划任务,无需用户使用 PowerShell 登录 - Create a scheduled task which runs every minute without the user being logged in using PowerShell 与创建该任务的另一个用户运行预定任务 - Run scheduled task with different user that the one that it was created 命令可以在命令行上正常运行,但不能从Task Scheduler运行 - Command runs fine on command line but not from Task Scheduler Windows 7计划任务命令行 - Windows 7 Scheduled task command line 使用任务计划程序计划的Powershell脚本无法运行…脚本运行正常 - Powershell script scheduled using Task scheduler doesn't run…script runs fine 如何将Rake任务作为Windows“计划任务”运行? - How can I run a Rake task as a Windows “scheduled task”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM