Pyinstaller *.exe in TaskScheduler

Question:

i created a small python program and freezed it to an *.exe file with the –noconsole option. When I run the program normally it works. But when I put it in the task scheduler that runs it on startup it does not work anymore.

The program has no ui. I know that it is not working because it is not writing to a log file. The paths in the program are absolute.

Any ideas what can cause this problem?

Asked By: user3166101

||

Answers:

You will need to do a little troubleshooting to narrow down the problem. I can share some tips.

  1. Make sure you have an exception handler for uncaught exceptions (at the very top) so you are logging those errors to a file. If you don’t have one you will never know why your program is crashing. Make sure if you add this you are re-throwing the exception after logging it so the os knows it crashed.
  2. Open the task schedule and run the task manually. Make sure the task is allowed to be ran manually (it’s in the configuration). If it is allowed to run manually, then it should have no trouble running automatically.
  3. The user you’re running the task with might be different from the user you are manually running it with. You can try removing the –noconsole option while you are trying to figure out the problem. If it is an issue with your logger not having write access where it needs to, you would not see anything in your logs but can see messages in the console.
  4. Make sure the working directory of the task is correct. By default it should use the same directory the app is in, but if a path has been entered it can cause issues.
Answered By: Timothy Jannace

In addition to Timothy’s ideas, make sure the option Run whether user is logged or not is activated, and if necessary, put the user password (when applying).

enter image description here

When you run a task on startup, the Windows session is not yet opened so the task may not run if Windows has no info how to open a session for it.

Answered By: DFE

I was trying to get information of Duplicati (Backup Software), but the server does start only when somebody is logged in. So the problem was not my program but the start of this other program.

Solved it through logging my program.

Answered By: user3166101