Task Scheduler Not Working Properly

I'm new to using Windows Task Scheduler for my work. I intend to run a script in Python to do scraping and send emails every day and every hour. At startup the task runs fine but not afterward. I have searched for solutions online and on YouTube but to no avail. What I have done is scan corrupt files and write the Start In parameters. My task configuration is as follows:

General Tab:

- Run whether user is logged on or not

- Run with highest privileges

- Configure for Windows 10

Triggers

- At startup

- Repeat task every 1 hour for a duration of 1 day

Actions

- Start a program

- Program/Script : my app directory

Conditions

- Wake the computer to run this task

Settings

- Allow tasks to be run on demand

- Run task as soon as possible after a scheduled start is missed

- if the task fails, restart every 1 minute for 3 attempts

- Stop the task if it runs longer than 1 hour

- if the running task does not end when requested, force it to stop

When I checked the history tab, the task was done successfully. But when I checked Event Viewer, there was an error when my script was run with Exception code 0xc0000409. Is there something I'm not paying attention to here? It would really help me if I got enlightenment. Thank You

Dear Reyhan Prasetyo,

Hello! Welcome to the Microsoft Community. I'm glad to be able to assist you. If I misunderstand your question, please let me know promptly.

It sounds like a challenge to know that you have a problem running Python scripts with Task Scheduler. I understand the confusion caused by this problem, and I will try my best to help you solve it.

According to what you mentioned, the task scheduler can work normally at startup, but there is a problem in the subsequent operation and the event viewer displays the exception code 0xc0000409, which usually indicates that some kind of access violation, stack buffer overflow or crash has been encountered. This may indicate that there is a problem with your script itself, or there is a problem with the environment in which the task scheduler runs when it is triggered. You can try the following methods, hoping they can help you:

1.Check the script running environment

- Ensure that Python is installed correctly: Ensure that the Python path used in the task scheduler -matches the installed Python version.

- Use full path: In the Program/Script field, make sure that the full path of the Python executable file is specified, for example, c: \ Python39 \ python.exe.

- Specify the full path of the script: in the Add Parameter field, pass the full path of your script, for example, c: \ path \ to \ your \ script.py.

2.confirm the Start In parameter:

Make sure to fill in the full path of the script directory in the "Start In" field, that is, the folder where your script is located. For example: C:\path\to\your.

3.Make sure the permissions are set correctly:

- Even if it is set to "Run with Highest Privilege", please ensure that all resources (files, networks) used in this script have appropriate privileges for the user to access.

- Check folder and file permissions. Make sure that the account running this task has access to these files or directories.

4.Add exception handling to the script: modify your Python script to ensure good error handling, such as using try-except blocks to catch and record exceptions. You can add logging to the script to help debugging.

5.Test Task Scheduler

- Separate testing: a way to run Python scripts separately (at the command prompt) to ensure that they work properly and avoid isolating problems.

- Simplify the scheduler configuration: When testing, you can temporarily remove the complex configuration, such as setting the trigger only once instead of repeating it every hour, which makes it easier to debug the problem.

6.Check more details in Event Viewer: In Event Viewer, check the detailed log corresponding to this task for details that may cause the crash.

7.Check resource usage: Make sure that all resources and libraries in the script are available at each run. For example, check to make sure that the network connection is normal if you rely on network requests.

8.Compatibility: Make sure that the Python version and all libraries you use are compatible with your scripts and Windows.

The above methods are some common solutions, and you may need to analyze the specific situation, because the problems may be different based on different environments.

I hope the above information can be of help to you. If you try the solution, please feel free to tell me the results or the problems you encounter.

Best Wishes

Pyked | Microsoft Community Support Specialist

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Dear Reyhan Prasetyo,

Hello! Welcome to the Microsoft Community. I'm glad to be able to assist you. If I misunderstand your question, please let me know promptly.

It sounds like a challenge to know that you have a problem running Python scripts with Task Scheduler. I understand the confusion caused by this problem, and I will try my best to help you solve it.

According to what you mentioned, the task scheduler can work normally at startup, but there is a problem in the subsequent operation and the event viewer displays the exception code 0xc0000409, which usually indicates that some kind of access violation, stack buffer overflow or crash has been encountered. This may indicate that there is a problem with your script itself, or there is a problem with the environment in which the task scheduler runs when it is triggered. You can try the following methods, hoping they can help you:

1.Check the script running environment

- Ensure that Python is installed correctly: Ensure that the Python path used in the task scheduler -matches the installed Python version.

- Use full path: In the Program/Script field, make sure that the full path of the Python executable file is specified, for example, c: \ Python39 \ python.exe.

- Specify the full path of the script: in the Add Parameter field, pass the full path of your script, for example, c: \ path \ to \ your \ script.py.

2.confirm the Start In parameter:

Make sure to fill in the full path of the script directory in the "Start In" field, that is, the folder where your script is located. For example: C:\path\to\your.

3.Make sure the permissions are set correctly:

- Even if it is set to "Run with Highest Privilege", please ensure that all resources (files, networks) used in this script have appropriate privileges for the user to access.

- Check folder and file permissions. Make sure that the account running this task has access to these files or directories.

4.Add exception handling to the script: modify your Python script to ensure good error handling, such as using try-except blocks to catch and record exceptions. You can add logging to the script to help debugging.

5.Test Task Scheduler

- Separate testing: a way to run Python scripts separately (at the command prompt) to ensure that they work properly and avoid isolating problems.

- Simplify the scheduler configuration: When testing, you can temporarily remove the complex configuration, such as setting the trigger only once instead of repeating it every hour, which makes it easier to debug the problem.

6.Check more details in Event Viewer: In Event Viewer, check the detailed log corresponding to this task for details that may cause the crash.

7.Check resource usage: Make sure that all resources and libraries in the script are available at each run. For example, check to make sure that the network connection is normal if you rely on network requests.

8.Compatibility: Make sure that the Python version and all libraries you use are compatible with your scripts and Windows.

The above methods are some common solutions, and you may need to analyze the specific situation, because the problems may be different based on different environments.

I hope the above information can be of help to you. If you try the solution, please feel free to tell me the results or the problems you encounter.

Best Wishes

Pyked | Microsoft Community Support Specialist

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 16, 2025 Views 622 Applies to: