How to automate the workforce scripts with Windows Scheduler

3559
19
Jump to solution
11-20-2018 12:50 PM
LaneHartman
New Contributor III

I'm looking for some guidance on modifying the assignment workforce scripts so I can use them with the windows scheduler and have them run in the background.  The scripts work great when I run them from the Python Command Prompt, but I'm not sure how to switch to Windows Scheduler automation. Just running the script as is in WinSch doesn't seem to work. Craig GillgrassAaron Pulver

Thanks

0 Kudos
19 Replies
GeorgeKatsambas
Occasional Contributor III

I had python scripts that ran perfectly in task scheduler, once we went to windows 10 task scheduler will no longer run the scripts as scheduled as its a security feature in W10 that would always require a login credential of an administrator. Are you using windows 10 and an administrator to your machine?

0 Kudos
daveostrander
Occasional Contributor II

That's a good question. I am running Windows Server 2016, and have noticed that privileges seem to matter a lot more on this new OS. So, when I run the script manually using Anaconda Prompt or Python Command Prompt I always need to right click and "run as administrator" in order for the script to succeed; if not it seems to fail when attempting to write to the log file on C:. My task is set to run with highest privileges, but not sure if that equates to run as administrator or not. That said, I am an administrator on this server. Just verified that by pulling up my account settings on the machine and can see the Administrator title below my username.

0 Kudos
by Anonymous User
Not applicable

You should be able to just add the following to the "Add arguments" text box:

C:\Users\username\some_script.py -u aaron -p password ...

0 Kudos
daveostrander
Occasional Contributor II

That is what has been so frustrating, is that it should be just that simple. So, I have now fixed the issue, but still have questions. I had installed pro, and then later installed python using the Anaconda Distribution. I was under the impression that I could use either python installation interchangeably, right? When I setup my task I pointed my "Program/Script" text box to C:\ProgramData\Anaconda3\python.exe, which did not work. I am not sure if it is a factor, but the default location that Anaconda 3.7 installs, also happens to be within a hidden folder (ProgramData). It wasn't until I changed the "Program/Script" section of Task Scheduler to "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" that it worked. All arguments were passed in without quotes, and everything is now working as expected. So why can't I execute from python.exe in the Anaconda3 folder?

Also, I am still having trouble running the workforce scripts straight from a standard Command Prompt. Each time I try to run the script from there I get an Import Error for module import_ssl (see below). Again, I haven't modified the underlying script (delete_assignments.py). Instead, I am just passing the parameters through. Any ideas on why this doesn't work? Is there something obvious that I am missing?

Anyway, thanks for all your help on this Aaron!

0 Kudos
daveostrander
Occasional Contributor II

It appears that the issues I was having were related to my system environment variables. With all of the installs of python floating around it was a bit confusing setting this up. On my server machine I have Python 2.7 installed with ArcGIS Desktop, Python 3.6.6 installed with ArcGIS Pro, and Python 3.7.1 installed with Anaconda. I also have a ArcGIS Pro clone that installs python in yet another location.

So, I have reset my system environment path variable to C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3, C:\Program Files\ArcGIS\Pro\bin\Python\Scripts, and C:\Python27. At this point everything appears to run correctly no matter which command line I use. Are these the recommended path variable settings? Previously I had the paths set to C:\ProgramData\Anaconda3, C:\ProgramData\Anaconda3\Scripts, and C:\Python27.

0 Kudos
MichaelVolz
Esteemed Contributor

George:

Have you resolved your problem on your Windows 10 desktop machine with running the python based Windows Scheduled Task?

0 Kudos
GeorgeKatsambas
Occasional Contributor III

No, when I add the python script windows 10 requires a password, when its scheduled to run and no password entered it wont run.

0 Kudos
GeorgeKatsambas
Occasional Contributor III

This keeps on popping up, only with python in task scheduler?

0 Kudos
MichaelVolz
Esteemed Contributor

Do you have both ArcMap and Pro installed on the Windows 10 machine?  If so, did you call the correct python environment to run?

Did the python Windows Sch. Task ever run on this computer?

0 Kudos
LaneHartman
New Contributor III

Haven't had your specific issue.  This was more script related. I've been able to run them on this machine with the "Run whether user is logged on or not" option on and "Run with highest privilege" checked. Also had to make sure I was using the correct path to the ArcGIS Pro python environment in the Action dialogue box.

0 Kudos