I have a Python script that needs to run nightly on several servers. I set up a scheduled task which runs on Windows Server 2008, but not on Windows Server 2012 R2. Originally, it was running as myself, but on 2012R2, it only runs when I'm logged in. I've tried running as a domain admin user and as the local SYSTEM account, but no luck. I've tried both setting a starting path to C:\Temp and leaving it black. I've tried running with highest privileges. Here is the exported task from my most recent test.
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2018-04-17T13:29:35.5882266</Date>
<Author>SYSTEM</Author>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2018-04-17T07:22:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-18</UserId>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Python27\python.exe</Command>
<Arguments>-m ecs_capacity</Arguments>
<WorkingDirectory>C:\Temp</WorkingDirectory>
</Exec>
</Actions>
</Task>
Running this while not logged on results in this:
Task Scheduler successfully completed task "\ECS Capacity Reports (ADM)" , instance "{168f0587-2c93-49c5-9913-a70d70346630}" , action "C:\Python27\python.exe" with return code 2147942401.
Things I've already looked at:
- Run batch file from Windows Task Scheduler regardless of user logged in suggests not using mapped drives, but I'm only accessing the C: drive.
- Unable to run a scheduled task in Windows Server 2012 R2 from Local Service account suggests running the task as Administrator; using my personal Administrator account also only works when logged in. Also, I am required to use a smartcard to log in as an Administrator, so trying to save my credentials doesn't work. (I can "check out" a password, but it's only good for 24 hours.)
- windows server 2012 task scheduler file not found (0x80070002) lists the exact symptoms, but has never been answered.