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?

0

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.

The problem is that using "schtasks /create /RU administrator /RP " to do so does not work as expected.

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. ".

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.

This fails. But if I create the scheduled task without specifying "/RU administrator" it works (if I run cmd.exe as local administrator).

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".

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.

Any way around this?

windows
scheduled-tasks
asked on Stack Overflow Jan 29, 2014 by Timje

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0