1

I'd like to schedule a python script to run weekly under Windows 7.

If I chooses "run only when user is logged on" and manually starts the task, the command window for the script would show up and it would work as expected.

If I chooses "run whether user is logged on or not" (and inputs the neccessary user information) and manully starts the task, nothing happens and it looks like the script didn't do anything. Also, the running result would be 0x1.

Any suggestion would be appreciated.

ps. "c:\python27\python.exe" is used as the command line and path_to_script.py as arguments. Also, I've specified "c:\python27" in the "start in".

Update 05/02/2017: The cause to the problem is said in Map a network drive to be used by a service, which means I shall not access network mapped drive directly in this mode.

Gang YIN
  • 2,509
  • 2
  • 21
  • 25
  • Try to use command line: `c:\python27\python.exe` and as arguments the complete path to the script: `c:\myScripts\myScript.py` – Maurice Meyer Apr 26 '17 at 12:56
  • @MauriceMeyer, sorry for not saying it clearly, actually that's what i'm doing right now, would update the question soon. – Gang YIN Apr 26 '17 at 12:57
  • 1
    Does a simpler script work? How about a simple command, like `-c "raise SystemExit(42)"`? Do other programs work when scheduled? For example, cmd.exe shouldn't fail. Is the user you're running as an admin with the right to do a batch logon? Is the script non-iteractive or does it create windows? With this type of logon, the task scheduler runs the program in the services session (0), which isn't allowed access to the graphical desktop. – Eryk Sun Apr 26 '17 at 14:38
  • @eryksun, a simple command (like just creating a new file under c:\) would work well. my script would access a network mapped drive and then do some file copying and then use Popen to start a new process for local file processing, any suggestion? – Gang YIN May 02 '17 at 12:11
  • @eryksun, thanks for your suggestion, looks like the reason is said here -- http://stackoverflow.com/questions/182750/map-a-network-drive-to-be-used-by-a-service. now i just use the original network path instead of a local mapped drive path and it works great! – Gang YIN May 02 '17 at 12:17
  • 1
    Yes, a network drive won't be available in the service-for-user (S4U) logon that you're trying to use. Using the UNC path may work, but not if it requires your full credentials. – Eryk Sun May 02 '17 at 12:36
  • I'm running into the same problem have no idea what you mean by Network drive. – Moondra Feb 11 '18 at 06:17
  • @Moondra, my script would access a network mapped drive (like mapping \\some-server\shared_path to Z:\), not sure if it's also the reason of the problem you encountered. Maybe you could try to comment out some code to find the root cause eventually. – Gang YIN Feb 17 '18 at 13:50
  • I had a python script that was trying to access the mapped network drive Z:\. Changing Z:\ to \\YourServerName\YourShareName\ solved the problem. The issue is that the "alias" Z: is only defined for the user, and [idiotically] there is no way to define it system-wide. Thanks Windows. – JoseOrtiz3 Jun 15 '18 at 08:50

0 Answers0