Python Script Running in Windows Task Scheduler Completes with exit code 3221225477 - python

I'm troubleshooting a python script that does 3 things.
Stops ArcGIS Server using subprocess.check_output('net stop "ArcGIS Server"', shell=True)
Runs some arcpy functions
Starts ArcGIS Server using subprocess.check_output('net start "ArcGIS Server"', shell=True)
The script runs fine when run from IDLE. It also runs fine as a scheduled task when I check the radio button that says "Run only when the user is logged on"
However, this task runs on a server and I don't want to have to be logged in for the task to run. So I check the radio button that says "Run whether user is logged on or not", and "Run with highest privileges".
The result is the script's log file is empty, and the script never completes. It returns the error code in the Task Scheduler, that I mentioned above.
More task details:
Action: Start a program
Program/script: C:\Python27\ArcGIS10.3\python.exe
Add arguments (optional): D:\ArcGISData\server-data\Python\copydata.py
Am I doing something wrong, or is there any other steps I can try to get this working?

Not sure why it wasn't working to be honest, but after going through the steps to recreate the task, it started working. Maybe I had just mistakenly entered the credentials of the user running the task or something like that.

Related

Windows Task Scheduler Last Run Result (0xF6)

What does Last Run Result (0xF6) mean?
I scheduled the Task Scheduler to run a *pythonw.exe with the arguments pointed to the *.py file.
User account is set for an admin account
Run whether user is logged on or not
Run with the highest privileges
Configured for Windows 10
I can't find a reference to this in a google search. Whatever is happening via the Task Scheduler I can't really tell because the python script does not finish-- meaning I can't read the log file to check how far it got or if it ran into any errors. If I run the script without the Task Scheduler it completes successfully.

Python to log in Windows automatically with task scheduler

I created a python script to automate a task.
I would like to run it every day on a hourly basis and for this I created a task in Windows Task Scheduler.
Is there a way to write a script to log in Windows automatically when my account is logged out, because my script fails if the Windows user is not logged in.
Thank you.
This is the wrong way to approach this. It's normal and expected that your computer will not always be logged in. You should not try to change that, as it would be very insecure.
The right thing to do is figure out why your script will not run when the system is not logged in. When setting your task up, you can set user credentials it should use when starting. Make sure your program is not making any incorrect assumptions about accessibility or security when it runs.

Windows Task Schedule 0X1 Error only when running when user is not logged in

On my personal computer, I created a bat file with a command to run a py script inside. It runs fine in the command line and runs fine in Task Scheduler when "run when user is logged in" is checked. However I need to run the task when the PC is asleep or not logged in. When I select "run when whether user is logged in or not", I get the 0x1 error.
I have tried toggling run with highest privileges but no avail. I am not sure what the issue is since the script runs now in a variety of environment (command line, python, pycharm).
Currently Task Scheduler's only field populated is script which is the address to my bat file \users\desktop\batfile.bat
The file's properties give read,write permissions to the appropriate users. I have searched on stackoverflow but the prescribed solutions have not worked for me. The py script modifies an excel spreadsheet if that is relevant.

Throw error on task scheduler when python script throws error

I have a python script. I have scheduled it to run monthly on Windows scheduler. However, it is prone to error sometimes and I would like to know if it threw an error. However the windows scheduler always shows the status as Successful. How can I make the Windows scheduler display the error or notify me if my .py script throws an error?
I don't believe you can show the information in Windows scheduler because it calls ShellExecuteEx() to run your program and that will report success no matter what return code your Python program issues. That is because the scheduler has successfully run the Python interpreter, which is all it cares about.
Have your program write the error to the Windows event log and look for it there. You can get fancy and set up the event log to notify you.

Python script involving Outlook through win32com runs when double-clicking, but not through task scheduler

I have a python script that sends out an email using win32com and Outlook. The script runs without a hitch when I run it through an interpreter or double-click on the script. However, when I run it through the Task Scheduler, I get the following message:
"Something went wrong. We couldn't start your program. Please try starting it again. If it won't start, try repairing Office from 'Programs and Features' in the Control Panel."
I'm using Office 365, and Python 2.6. I've tried running the script through the scheduler after killing the Outlook process, but I ran into the same issue.
Office isn't designed to run as a service, and needs to be run interactively. You'll need to change your task configuration in Task Scheduler to run the task as the currently logged-in user, on the current user's desktop, with the current user's privileges.

Categories

Resources