guide · static export
Productivity

Run a Script at Logon With Task Scheduler

The startup folder is convenient and unreliable: it runs after the desktop appears, with the wrong working directory. A scheduled task is the better tool.

by@guidox updated:10/31/26 time:20 min level:Intermediate tested on:Windows 11 24H2 works on:Windows 10, Windows 11 tools:Admin rights
TL;DR

Create a task with the trigger **At log on**, set the action to your script with the full path, and tick **Run with highest privileges** if it needs admin. A .ps1 file needs **powershell.exe** as the program and **-File** as the argument.

Before you start

Requirements

  • Admin rights
  • A script file
  • Twenty minutes
Step by step

Instructions

01

Decide what the script needs

A task that maps a drive, starts an app or copies files has different requirements from one that edits services. Admin rights and the user context decide which account the task runs as.

02

Create the task, not the basic one

The create dialog offers the full set of triggers and conditions. The basic wizard hides the settings that make the task reliable.

taskschd.msc > Create Task
tipGive the task a folder of its own under the task library root. Your own tasks stay findable and safe from cleanup tools.
03

Set the trigger and the delay

At log on plus a two-minute delay avoids competing with the shell and the network stack during sign-in. A task that needs the network fails silently without one.

04

Point the action at the interpreter

For a PowerShell script the program is powershell.exe and the arguments carry the file path and the execution policy. Pointing the task at the .ps1 directly opens an editor window instead.

-NoProfile -ExecutionPolicy Bypass -File C:\cripts\ogon.ps1
⚠ warningSet the start-in folder as well. A script with relative paths fails in a task while working fine when you double-click it.
05

Decide about the account

Run only when the user is logged on shows a window; run whether logged on or not runs hidden and needs the stored password. A task that must interact with the desktop needs the first option.

06

Test with Run, then check the history

The task history records the last result code and the exit code of the script. A zero means success; anything else tells you the script or the path failed.

Troubleshooting

Common issues

The task runs but nothing happens

Working directory or user context. Log the script output to a file to see what it did.

The task never fires

The trigger is wrong or the task is disabled. Check the next run time in the list.

It works on Run and not at logon

The network is not ready yet. Add the delay or wait for a network condition.

Execution policy blocks the script

Pass -ExecutionPolicy Bypass in the arguments rather than changing the machine policy.

FAQ

Frequently asked

Is the startup folder ever better?

For a quick user-level action with no privileges it is simpler.

Can the task run before sign-in?

Yes with a boot trigger and a service account, and it cannot show a window.

How to undo this

Delete the task from the task library. Nothing else changes, and the script file stays where it is.

Changelog · 1 entry
  1. 2026-10-31
    First version
Interactive version: checklist, feedback, related guides →

Free · no account needed · tracks your progress