[Tutor] How to make a python script run on startup

eryksun eryksun at gmail.com
Tue Apr 9 21:41:15 CEST 2013


On Tue, Apr 9, 2013 at 12:35 PM, Dave Angel <davea at davea.name> wrote:
> But does anything in the startup folder run BEFORE any user logs in? It's
> been a long time since I had to run Windows, but I didn't think so.

The contents of the startup folders are executed in the current
session after logon. The same applies to run keys such as
"HKLM\Software\Microsoft\Windows\CurrentVersion\Run".

I wasn't taking "startup" to mean literally before any user has logged
on. But yes, if that's the requirement, you can use the Task Scheduler
service to start a program as a batch process in session 0 (or instead
create your own service).

Just as an FYI, in the "Home" versions of Windows the task scheduler
can't store logon credentials, so to run at startup you have to use
LOCALSERVICE or SYSTEM.

To automate creating a task use the "schtasks" command. For example,
to create a task named "Python" that runs python.exe at startup under
the LOCALSERVICE account, execute the following from an elevated
shell:

schtasks /Create /TN Python /RU LOCALSERVICE /SC ONSTART /TR
C:\Python33\python.exe

This will run as a non-interactive service in session 0. There won't
be a visible GUI or console window to interact with in your desktop
session.


More information about the Tutor mailing list