4

I am trying to create a scheduled task to run a batch file. I know that my batch file runs fine, because I have no problem running it manually. However, when the task calls it, it says that it's running, but it's not. The reason I know that it's not running is because it calls a python script, and the python script sends an email saying that the process has started. And I'm not receiving that email.The python process doesn't take too long (maybe 5 minutes at most), and the task keeps saying that it's "Running" after an hour.

I have the current settings with "Run whether user is logged on or not" (doesn't seem to work at all if I have it as "Run only when user us logged on", because the status never changes from "Ready" even if I tell it to run). I also have the setting with "Run with highest privileges", and just the name of the batch file under "Program/script" and the path to the batch file under "Start in". I also want to note, that I have the user account as "DOMAIN\Administrator".

However, I've tried other ways of calling it. I've tried putting the entire path with the batch file under "Program/script" (G:\GOM3_Update\FeatureServices\copies\test.bat), or putting the path to the python program, and then putting the path to the python script as an argument, but that doesn't seem to work either.

I'm not sure if this issue is caused by some major security settings with windows 10, or something minor in the task scheduler settings.

Here are my current settings:

enter image description here

Full path of the Start in is: "G:\GOM3_Update\FeatureServices\copies\"

enter image description here

The batch file:

"C:\Users\Administrator.DOMAIN\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\python.exe" "G:\GOM3_Update\FeatureServices\copies\database.py"
earthsci0909
  • 41
  • 1
  • 3
  • If you look at task manager, do you see cmd.exe running? My guess is that the task is running, but the batch file is "stuck" -- probably with an error message you can't see. – avery_larry Nov 26 '19 at 03:39
  • I recommend to first read [What must be taken into account on executing a batch file as scheduled task?](https://stackoverflow.com/questions/41811209/) Many batch files work fine on double clicking them, but fail to run as scheduled task because of the environment is different and that is not taken into account in the batch file. What does the batch file contain? If it contains just one line to run `python.exe` with full qualified file name enclosed in double quotes with the python script file as argument also with full qualified name within `"`, a batch file is not needed at all. – Mofi Nov 26 '19 at 05:51
  • @Mofi I just added a screenshot of my batch file. I have tried running the task without using a batch file by entering the path to the python.exe under "Program/script", and the path to the python script as the argument, but that doesn't seem to work either. It gives me the same problem. – earthsci0909 Nov 26 '19 at 20:25
  • Posting the text in a batch file is better than a screenshot in most cases. In this case though your path to python.exe is malformed. `,`should not be there. – somebadhat Nov 26 '19 at 20:33
  • comment me when you have done the following: If the task has more than one Action remove the screenshot of the "edit action" dialog and replace it w/ a screenshot of the "Actions" tab. Run your batch manually in a cmd window w/ and w/o admin privileges. Is there a difference? – somebadhat Nov 26 '19 at 20:41
  • Keeping in mine that the windows 10 task scheduler does not refresh every object of the currently open window w/o interaction, does your task not run? Or did you just not check the history tab? With the unreliability / time lag of email have your python script pop up a message on your display instead. – somebadhat Nov 26 '19 at 20:42
  • If you insist on using a batch file named `test.bat`, where is it located? My reason for asking is that you didn't respond to @Mofi's comment, and item 2 of their linked answer, tells you that `%SystemRoot%\System32\test.bat` is what it usually tries to run. _Obviously all unqualified paths in the batch file will also be relative to `%SystemRoot%\System32` too!_ You can assume this behavior for running it under another user too, things will be relative to their default location. – Compo Nov 26 '19 at 21:11
  • @avery_larry I see it running, but then it disappears quickly – earthsci0909 Nov 26 '19 at 21:59

2 Answers2

2

I would include a full path to batch file here: enter image description here

From my personal experience it is usually the environment problem, aka things like current working directory etc..

Also, make sure to click the refresh button in the right pane of Task Scheduler because it is known for not updating the status of task unless you manually refresh. You may see it change from 'running' to 'ready' sooner if you do that. The reason why I feel like your screen is not refreshing is because normally Task Scheduler does not allow any scheduled task to execute for longer that 1 hour and you said yours was still saying 'running' after an hour.

What does the exit code and messages say under tasks history? enter image description here

Exit code 0 means no errors captured by Task Scheduler.

Another idea is to log the start of batch script (inside batch) to a log file before you do anything. And do the same for python file. This will help you narrow down the problem.

andrewlis
  • 41
  • 1
  • 9
0

I struggled with this one also a lot, changing the User Account enter image description here

AND Group. User Account alone was not enough for me.

This helped for me:

enter image description here

And then clicking on the Locations...you'll have to choose "WINSTADM" enter image description here

thijs
  • 761
  • 6
  • 7