Scheduled task won't run .py file in windows 10 for 'Run whether user is logged on or not' option

Viewed 2872

I have a python file 'Test.py' which runs a selenium python script of logging in and logging out my account. I've to login at 9 am and logout and 1 pm. So, I want to run a task scheduler for this.

File folder : C:\Users\knsai\Test.py and python exe location : C:\Users\knsai\AppData\Local\Microsoft\WindowsApps\python.exe

If I run the task "Run only when user is logged on" everything works fine, the selenium script is executed by opening chrome driver.

If I run the task "Run whether user is logged on or not" using the same user as above, there is no response(It doesn't give even any error). I've also enabled 'Run with highest privileges' and made sure the Author and Security Options have the same account.

FYI: I've created empty desktop folder as mentioned in this Task Scheduler (run whether user is logged on or not) but it doesn't work.

enter image description here

2 Answers

It finally worked for me when I created a Batch File to run my python script, refer Create a Batch File to run Python Script link to "Create a Batch File to run Python Script".

Later, I followed this video to configure a "Task Scheduler " with Batch File to configure a "Task Scheduler " with Batch File

But I still have one doubt in my 'Test.py' I'm invoking my chrome driver and hitting a link and closing it after a few clicks. I cannot see GUI(opening chrome) when the task runs but I got my desired output (that means the program actually runs) without showing me the chrome driver. How can this happen?

It's late but thought to post since I had a similar issue when select the 'Run whether user is logged on or not' option. Below are some points that you can try out. I had to do the bold options in order to make it work.

  • Try creating a new task, but select the Configure for: option to be “ Windows Server 2003, Windows XP, or Windows 2000 ” – this will create an XP/2003 fashioned task
  • Select the “ Run with highest privileges ” option under Security on the General tab
  • If you are launching a Batch script (.vbs/.cmd/.bat/.ps1), modify your script to add some type of logging to see where it may be failing – see the following blog for examples: Two Minute Drill: Quickly test Task Scheduler
  • If running a .vbs / .ps1 script, try launching it from a .cmd / .bat script – for example: “ cscript.exe myscript.vbs” would be in my .cmd/.bat script, and I would then launch it from my Scheduled Task
  • Check your scripts for environmental issues – when we run a script, we default to the “%SystemRoot%\System32” folder unless specified in the script (i.e. CD C:\Scripts\Test)

Please refer below blog for more information,

Help! My Scheduled Task does not run…

Related