Blog | G5 Cyber Security

Run Scripts on Windows Login

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

  1. Open Task Scheduler: Search for “Task Scheduler” in the Start menu and open it.
    • Alternatively, press Windows Key + R, type taskschd.msc and press Enter.
  2. Create Basic Task: In the right-hand pane of Task Scheduler, click “Create Basic Task…”.
  3. Name Your Task: Give your task a descriptive name (e.g., “Run My Script”) and add an optional description. Click “Next”.
  4. Choose Trigger: Select “When I log on” as the trigger for when the task should run. Click “Next”.
  5. Select Action: Choose “Start a program” as the action. Click “Next”.
  6. 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 Bypass part is important if your scripts aren’t digitally signed; it allows them to run.
    /c "C:ScriptsMyBatchFile.bat"
  7. Finish: Review the task details and click “Finish”.
  8. (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.
  9. 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:

Exit mobile version