I am trying to run a Python program in a cmd.exe window via Task Scheduler on Windows 10. I’m having problems.
- OS: Windows 10
- Python: 3.11.9
- We use a network and a VPN and I have to log in to our Active Directory. I’m connected to the VPN already.
- Task setup
- Command line:
c:\windows\system32\cmd.exe
. I have verified that cmd.exe exists there. - Task Parameters: This calls a batch file where I gave the task the full path:
/k C:\Users\MYUSER\OneDrive - COMPANY\Documents\PythonProjects\COMPANY\Test\Proforma\godailyauto.bat
. - I have also used a command line of
runas.exe
and parameters of/user:chuck c:\windows\system32\cmd.exe /k "C:\Users\MYUSER\OneDrive - COMPANY\Documents\PythonProjects\COMPANY\Test\Proforma\godailyauto.bat"
but that gives me the same errors.
- Command line:
- The batch file
godailyauto.bat
that is called first sets the Path variable to include the Python exe file and Python variables. It then runs the program with full paths like this:C:\Users\MYUSER\AppData\Local\Programs\Python\Python312\python C:\Users\MYUSER\OneDrive - COMPANY\Documents\PythonProjects\COMPANY\Test\Proforma\proforma.py -overwrite -email -subject:"Test: proforma report 7:17" -limit:50
- When I change and save the task properties Windows asks me for a username and password. My username is filled in so I enter my password, and I don’t get an error here.
When I run the program manually from the command line it works fine and a log file is updated with the date and time it ran.
When I run this task in the Task Scheduler v1.0 I get these errors:
- “Task Scheduler failed to start “\crProformaTest” task for user “COMPANY\chuck”. Additional Data: Error Value: 2147942667.”
This normally means “access denied” but I can’t seem to find a solution.
Any ideas why this isn’t working? I’ve done some searching online and have not found anything that fixes my problem yet. I’ve tried some variations as documented above and still I get an error in the Task Scheduler log.
Thank you!