3

I have a scheduled task that is set to run an R script by launching Rscript.exe and the file of interest.

This task completes successfully when I run it with the option

"Run only when user is logged on".

I need to schedule the task to run without me, so I checked the option:

"Run whether user is logged on or not"

and gave it my password.

I needed to test this and thus clicked "run" only to watch it immediately fail with a result of

0x1

There is a log file created by R when the script runs, however the scheduled task apparently failed before this log was created.

I found this resource, which says that when the task cannot be successfully run manually when the "whether user is logged on or not" option is checked.

With that in mind I instead scheduled the task to run a few minutes in the future. The task again failed with the 0x1 run result before launching Rscript and thus creating a log.

I repeated this process and few times and the result was the same each time.

When I look at the task's properties I see that in 1 second of time it reached the "Action Completed" step which returned a non-zero return code and failed with an Operational Code of "(2)".

enter image description here

The task definition is:

Action: Start a program Program/script: cmd Add arguments: /c E:/PROGRA~1/R/R-33~1.1/bin/Rscript.exe T://code//Forecast.R >> T://code//Forecast.log 2>&1 
10
  • Anything in Event Viewer? Can you post the task definition? Commented Aug 10, 2016 at 21:56
  • @dsolimano Excellent questions. I will absolutely follow up on these first thing tomorrow morning. Commented Aug 10, 2016 at 22:16
  • @dsolimano I've updated the question with the task definition. The task also failed this morning when it tried to run at it's daily scheduled time of 9:00am. I don't see anything related in Event Viewer. Commented Aug 11, 2016 at 14:09
  • Hmm, are E and T local drives, or network mappings? If they're network mappings, how do they get set? Might not be getting set by the batch logon process. Commented Aug 11, 2016 at 14:12
  • @dsolimano E:/ is local T:/ is a network drive. I probably don't fully understand this aspect in terms of how it gets set; I only know that T:/ is always available in the Explorer on this server and to apps like RStudio on this server. I will try moving the script from T:/ to a local drive and see if that helps. Commented Aug 11, 2016 at 14:14

1 Answer 1

1

You need to have the "Log on as a Batch Job" security right to run a task as a user.

Admin Tools -> Local Security Policy -> Local Policies -> User Rights Assignment -> Log On as a Batch Job.

I'm sure in the event viewer you'll see a security event with a failed logon attempt with a logon type of 4 (batch job).

1
  • I added my username to "Log On as a Batch Job" and scheduled it to run in 5 minutes, but it was still unsuccessful with the same result codes as before. I think I was already included in "Log On as a Batch Job" by virtue of some of the user groups I'm in. I don't see anything related in Event Viewer. Commented Aug 11, 2016 at 14:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.