The accepted answer is the way to do it, if you want your script running early in the system startup, or need the script to run synchronously - that is, the normal logon process will continue only after your script has completed (watch out, it can slow down logon, use it only if you need it).
Note: I'm not sure if the scripts mentioned above can be an .exe
file or not, but in the method I will describe any executable can be used.
Another way to do, which has some extra flexibility, is using the Task Scheduler
. From the start menu, type Task Scheduler and run it (or run taskschd.msc
from Run
dialog or a shell). Select Task Scheduler Library
in the tree view. If you want, you can create a special subfolder for your programs, but this is not necessary. Click Create Basic Task...
(wizard) or Create Task...
in the Actions
panel on the right side.
I will explain how to use Create Task...
.
- In the
General
tab, fill out a descriptive name and, optionally, a description for your task.
- In the
Triggers
tab, click New...
, set Begin the task
to At log on
. Check the Specific user
combobox, make sure your username is selected (you can use Any user
if you want the program to run when any user logs in). If you don't want your script to slow down the log in process, you can choose to run it after a delay - click Delay task for
checkbox and type in the time (e.g. 30 seconds
). Click ok to create the trigger.
- In the
Actions
tab, click New...
, choose your program (or script) using Browse...
or type in the full path into Program\program
. If the program is in your %Path%, you can just use program
. You may specify any arguments to pass to the program in Add arguments
. You may specify the working directory for the program in Start in
. You can use any type of script the local computer supports; if a script type is not registered with Windows, you can still run it by specifying the script interpreter as the program. E.g. use C:\path\to\python.exe
as the program, and C:\path\to\script.py some_arguments
as arguments. Click ok to create the action.
- In the
Conditions
tab, you probably want to uncheck the Start the task only if the computer is on AC power
.
- In the
Settings
tab, there is no need to change anything.
Click ok to create the scheduled task. If you want to edit it later, just select Task Scheduler Library
in the tree view, find your task in the list (at top part of the window) and double-click the task.
See the Task Scheduler reference for more information.
1In a standalone system, is there any advantage in configuring a logon script over just putting it in the Startup folder? – user1686 – 2011-03-21T09:15:31.383
2The advantage is that the script will be loaded very early, e.g. before launching other applications. This is very useful to mount encrypted partitions. – Mike L. – 2011-03-21T12:30:01.797