1

On my personal computer, I created a bat file with a command to run a py script inside. It runs fine in the command line and runs fine in Task Scheduler when "run when user is logged in" is checked. However I need to run the task when the PC is asleep or not logged in. When I select "run when whether user is logged in or not", I get the 0x1 error.

I have tried toggling run with highest privileges but no avail. I am not sure what the issue is since the script runs now in a variety of environment (command line, python, pycharm).

Currently Task Scheduler's only field populated is script which is the address to my bat file \users\desktop\batfile.bat The file's properties give read,write permissions to the appropriate users. I have searched on stackoverflow but the prescribed solutions have not worked for me. The py script modifies an excel spreadsheet if that is relevant.

Steve Burt
  • 69
  • 1
  • 8
  • The option to run when the user isn't logged on is based on a service-for-user (S4U) batch logon in the non-interactive services session (i.e. session 0). The user needs to have the batch logon right -- typically an administrator -- and the process cannot depend on user interaction. – Eryk Sun Oct 31 '19 at 21:40
  • Also, you don't need to use a batch script for this. The task can directly run the fully-qualified path of python.exe or py.exe, with the fully-qualified script path passed as the command-line argument. – Eryk Sun Oct 31 '19 at 21:41
  • @ErykSun the script opens an excel, adjusts a cell saves and closes it. Does that constitute user activity? – Steve Burt Nov 02 '19 at 18:19
  • Yes, I don't think Excel can run in the services session, but you should use the logging module to log more information about why your script fails. If Excel is the problem, then you'll need to use a library that can directly modify Excel spreadsheets instead. – Eryk Sun Nov 02 '19 at 22:33

0 Answers0