I am trying to run a python script with Windows Task Scheduler but the Last Run Result is 0x2331 for some reason. This error seems to indicate a windows path issue.
Dependencies
I am using Windows 10 Pro (64 bit)
and the absolute path to my python executable is C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe.
My python script
The absolute path to my python script is C:\Users\user\.spyder-py3\AutoScript\test.py. It simply writes the current time to a text file. If text file does not exist, it creates the text file:
# -*- coding: utf-8 -*-
import datetime
with open('C:/Users/user/.spyder-py3/AutoScript/readme.txt', 'a+') as f:
f.write(f'{datetime.datetime.now()}\n')
If I run the script normally in Spyder 3 IDE (Anaconda 3) with Python 3.9.7, readme.txt gets created with no errors and the file content is as expected. Therefore, there are no issues with the script.
Creating task with Task Scheduler
I have included screenshots of the settings in Task Scheduler. Click on the images to view them in high resolution.
Result
When I run the task on Task Scheduler and then refresh Task Scheduler, the "Last Run Result" of my task is (0x2331).
What I tried
I tried messing around with the different settings in Task Scheduler with no success. The first 3 columns represent the settings details and the last column contains the result obtained.
| Program/script | Add arguments : | Start in : | Last Run Result |
|---|---|---|---|
| C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe | C:\Users\user.spyder-py3\AutoScript\test.py | (0x2331) | |
| "C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe" | "C:\Users\user.spyder-py3\AutoScript\test.py" | (0x2331) | |
| C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe | test.py | C:\Users\user.spyder-py3\AutoScript\ | (0x2331) |
| C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe | "test.py" | C:\Users\user.spyder-py3\AutoScript\ | (0x2331) |
| "C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe" | "test.py" | "C:\Users\user.spyder-py3\AutoScript" | The directory name is invalid (x8007010B) |
| "C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe" | "test.py" | C:\Users\user.spyder-py3\AutoScript\ | (0x2331) |
Batch file
Using this post as reference, I also tried placing using a executePy.bat file. It was placed in the same folder as test.py.
executePy.bat:
@echo off
"C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe" "test.py"
The settings in Task Scheduler were as follows:
| Program/script | Add arguments : | Start in : | Last Run Result |
|---|---|---|---|
| C:\Users\user.spyder-py3\AutoScript\executePy.bat | (0x2331) |
None of the above changes solved my issue. Any help is appreciated. Thanks.



