TL;DR
Automatically run commands or scripts every time you log into your Windows computer using Task Scheduler. This guide shows you how to set it up.
How to Auto-Run Scripts on Windows Login
- Open Task Scheduler: Search for “Task Scheduler” in the Start menu and open it.
- Alternatively, press
Windows Key + R, typetaskschd.mscand press Enter.
- Alternatively, press
- Create Basic Task: In the right-hand pane of Task Scheduler, click “Create Basic Task…”.
- Name Your Task: Give your task a descriptive name (e.g., “Run My Script”) and add an optional description. Click “Next”.
- Choose Trigger: Select “When I log on” as the trigger for when the task should run. Click “Next”.
- Select Action: Choose “Start a program” as the action. Click “Next”.
- Configure Program/Script: This is where you tell Windows what to run.
- Program/script: Enter
cmd. - Add arguments (optional): Here’s how to specify your script:
- To run a batch file (.bat or .cmd), enter
/c "C:pathtoyourscript.bat"(replace with the actual path). - To run a PowerShell script (.ps1), enter
/c powershell -ExecutionPolicy Bypass -File "C:pathtoyourscript.ps1"(replace with the actual path). The-ExecutionPolicy Bypasspart is important if your scripts aren’t digitally signed; it allows them to run.
- To run a batch file (.bat or .cmd), enter
/c "C:ScriptsMyBatchFile.bat" - Program/script: Enter
- Finish: Review the task details and click “Finish”.
- (Optional) Configure for Hidden Running & Highest Privileges: Sometimes you need a script to run without showing a command window, or with administrator rights.
- Right-click on your newly created task in Task Scheduler.
- Select “Properties”.
- General Tab: Check the box “Run whether user is logged on or not” if you want it to run even when no one is actively logged in (requires saving credentials).
- Configure for highest privileges: Check the box “Run with highest privileges”.
- Hidden Tab: Check the box “Run hidden” to prevent a command window from appearing.
- Test Your Task: Log off and log back in to see if your script runs as expected.
- You can also right-click on the task in Task Scheduler and select “Run” to test it immediately.
Important Notes:
- Replace
C:pathtoyourscript.batorC:pathtoyourscript.ps1with the correct path to your script file. - If you’re using PowerShell, ensure that script execution policy allows running scripts. Using
-ExecutionPolicy Bypassis a quick fix but consider more secure options for production environments. - Check Task Scheduler history (enable it in properties if needed) for any error messages if the task doesn’t run correctly.