Python – Scheduler not working on windows server 2016 EC2 instance aws, while EC2 is running

amazon ec2batch-filepythonscheduled-taskwindows-server-2016

I have setup a few batch files to execute python scripts on window. I have confirmed the batch files work by double click them which lauches CMD to show the scripts running.

I have setup a task scheduler to kick off the batch files, and tested it by hitting the 'run' button on task scheduler GUI.

The EC2 instance is always up and running, but when I close my Remote Desktop application for the EC2 instance, the task scheduler does not kick off my scripts. What am I doing wrong? I want the task scheduler to run regardless if I can see the desktop or not.

I am using a mac to remote into the EC2 instance if that helps. Also very new to working with windows as indepth as this.

Thank you in advance.

Edit:

bat file settings:

@echo off
python C:\folder\folder\pythonscript.py %*
pause

Scheduler settings:

General Tab:
(checked) Run whether user is logged on or not
(checked) Run with highest privileges
Running as admin on local computer

Trigger Tab:
(checked) Daily
Recur every 1 day
(checked) repeat task every 1 min for duration 'indefinite" ----this is for testing
(checked) Enabled

Actions Tab:
Action: start a program
Program/script: C:\folder\bat_files\test.bat
Add Arguments(optional): blank
Start In(optional): blank

Conditions Tab:
(checked) start the task only if the computer is on AC power
(checked) Stop if computer switches to battery power
(checked) Wake the computer to run task

Settings Tab:

(checked) Allow task to be run on demand
(checked) Run task as soon as possible after schedule is missed
(checked) if task fails, restart every 1 min

Best Answer

There could be multiple things but as per the description you provided If every setting is correct in Windows Task scheduler and running fine when System user login with GUI mode it could be related to the python script which might require a constant GUI mode to execute. You can also check the same task on your local system.

Also, check below link if it can be Sysprep related and post further. https://support.microsoft.com/en-in/help/253942/fix-task-scheduler-task-only-runs-in-the-background-after-you-use-sysp