ratherstrange
ratherstrange

Reputation: 117

Windows task scheduler not running python script/batch file

I have a very simple python script (to send an email) which works perfectly when I run it in the cmd window, or in python, or if I directly start a a .bat file pointing to it.

However, when I try to get the task scheduler to run it, nothing happens. The task scheduler says that it runs and completes successfully, the log file is blank, but no email is sent.

I'm aware there are a lot of other questions relating to this problem, and I've read through them and tried the solutions, but nothing seems to work. I am new to python (and to scheduling tasks!), so I may be implementing the solutions incorrectly.

Here is what I've tried...

All of these work fine when double clicking on the file - but none run in task manager. (Although they say they have completed successfully). In task manager I just put the link to the .bat file in the "Program/script" box.

Some of the ones where I try to run the script.py directly just say "running" in the Task Scheduler forever, but I didn't note down which these were.

I'm running Windows 7 (64bit), and have got Python 3.5.1 (32bit). I've got local admin rights.

Other scheduled tasks I have created (not involving a python script) work fine, but this has stumped me. Please help!

Upvotes: 0

Views: 3889

Answers (3)

elesh.j
elesh.j

Reputation: 344

For me, specifying the "start in" directory worked:

Define Start in directory in properties of scheduled task. Start Windows Task Scheduler. Navigate to the task and double click on it to open the Properties of the task. Select tab Action and click on button Edit. There is Start in (optional). Enter here the path of the executed batch file. Click two times on button OK to save this important modification in properties.

Upvotes: 0

Anton
Anton

Reputation: 940

Something else to try:

Make sure in your batch file you're adding a command to change directories to where your executable lives.

@echo off
echo.------------------------------------------------   
echo.Windows Task invoked on %date%, %time% (local time)
echo.------------------------------------------------   

SET My_exe_dir="C:\Program Files (x86)\MyProgram\FolderWhereExeLives"

SET Input_dir="C:\Program Files (x86)\MyInputFolder"

cd %My_exe_dir%  <-- This was the key for me.

%My_exe_dir%\myprogram.exe %Input_dir%\MyInputFile.xml -1

Upvotes: 0

ratherstrange
ratherstrange

Reputation: 117

Just adding an answer in case this affects any other newbie :). I needed to check "Run only when user is logged on", and also uncheck "Run with highest privileges".

I'm guess this is because as eryksun says Outlook has a GUI.

Upvotes: 2

Related Questions