Windows applications do not always need to be installed as Windows Services to run continuously in the background. For lightweight command-line programs, agents, proxies, synchronization tools, and similar utilities, Task Scheduler provides a built-in and relatively clean way to achieve:

  • automatic startup with Windows;
  • background execution without opening a console window;
  • execution before any interactive user logs in;
  • running under the SYSTEM account;
  • optional delayed startup;
  • continuous execution without the default 72-hour runtime limit.

This article uses a generic command-line program named agent.exe as an example.

1. Example directory structure

Assume the program is stored under:

C:\Tools\agent\
├── agent.exe
└── agent.toml

Before configuring automatic startup, the program should first be tested manually:

cd C:\Tools\agent
.\agent.exe -c .\agent.toml

If the program starts successfully and connects to its target service as expected, stop the foreground test with:

Ctrl+C

Only after manual execution has been verified should automatic startup be configured.

2. Why use Task Scheduler?

Several common approaches exist for starting programs automatically on Windows:

  • Startup folder;
  • registry Run entries;
  • Windows Services;
  • third-party service wrappers;
  • Task Scheduler.

For command-line programs that need to run permanently in the background, Task Scheduler has several advantages.

A task can start at system startup rather than user logon. It can also run as SYSTEM, meaning that it does not depend on a particular desktop session.

This is especially useful for applications that behave more like infrastructure components than normal desktop applications.

3. Create the startup task

Open PowerShell as Administrator and run:

schtasks.exe /Create `
  /TN "BackgroundAgent" `
  /SC ONSTART `
  /DELAY 0000:30 `
  /RU SYSTEM `
  /RL HIGHEST `
  /TR '"C:\Tools\agent\agent.exe" -c "C:\Tools\agent\agent.toml"' `
  /F

The important parameters are:

/TN "BackgroundAgent"

Defines the task name.

/SC ONSTART

Runs the task when Windows starts.

/DELAY 0000:30

Delays execution by 30 seconds.

This is useful for network-dependent programs because Windows networking, DNS, VPN components, physical adapters, and other services may still be initializing immediately after boot.

/RU SYSTEM

Runs the program as the Windows SYSTEM account.

The task therefore does not require an interactive user to log in.

/RL HIGHEST

Runs the task with the highest available privileges.

/TR

Specifies the executable and its arguments.

/F

Overwrites an existing task with the same name.

A successful result looks similar to:

SUCCESS: The scheduled task "BackgroundAgent" has successfully been created.

4. Test the task without rebooting

There is no need to reboot immediately.

Start the scheduled task manually:

schtasks.exe /Run /TN "BackgroundAgent"

Then verify that the process exists:

Get-Process agent

A typical result might look like:

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    150      11    18000      16500       0.20   4200   0 agent

One particularly useful detail is:

SI 0

Session ID 0 normally indicates that the process is running in the Windows system service session rather than inside the currently logged-in desktop session.

That is consistent with a task running under SYSTEM.

5. Inspect the scheduled task

Use:

schtasks.exe /Query /TN "BackgroundAgent" /V /FO LIST

Important fields include:

Status:                               Running
Scheduled Task State:                 Enabled
Run As User:                          SYSTEM
Schedule Type:                        At system start up

These values confirm that the program is:

  • currently running;
  • enabled;
  • running as SYSTEM;
  • configured to start when Windows boots.

6. Remove the default 72-hour runtime limit

This is an easy detail to miss.

A Task Scheduler task may have an execution time limit such as:

Stop Task If Runs X Hours and X Mins: 72:00:00

That behavior is unsuitable for programs intended to run continuously.

Use PowerShell to disable the execution time limit:

$task = Get-ScheduledTask -TaskName "BackgroundAgent"
$task.Settings.ExecutionTimeLimit = "PT0S"
$task | Set-ScheduledTask

PT0S means that no execution time limit is imposed.

Verify again:

schtasks.exe /Query /TN "BackgroundAgent" /V /FO LIST

The relevant line should now show:

Stop Task If Runs X Hours and X Mins: Disabled

This is an important step for proxies, agents, tunnels, synchronization daemons, monitoring processes, and other long-running applications.

7. Understanding Last Result: 267009

While a long-running task is active, Task Scheduler may display:

Last Result: 267009

The hexadecimal form is:

0x41301

This means that the task is currently running.

It is not an application failure.

For continuously running background programs, seeing this value while the process is active is therefore normal.

8. Battery-related behavior

A default scheduled task may also show:

Power Management: Stop On Battery Mode, No Start On Batteries

This means that Windows may:

  • refuse to start the task while the machine is running on battery;
  • stop the task if AC power is disconnected.

For a desktop or permanently powered machine, this setting may not matter.

For a laptop that must keep the background application active on battery power, the task settings should be adjusted accordingly.

The current settings can be inspected with:

(Get-ScheduledTask -TaskName "BackgroundAgent").Settings

Battery behavior should only be changed when continuous operation on battery is actually required.

9. Stop the background task

To stop the scheduled task:

schtasks.exe /End /TN "BackgroundAgent"

Alternatively, terminate the process directly:

Stop-Process -Name agent

The first method is generally preferable when the program was started through Task Scheduler.

10. Disable or delete automatic startup

To disable the task without deleting it:

Disable-ScheduledTask -TaskName "BackgroundAgent"

To enable it again:

Enable-ScheduledTask -TaskName "BackgroundAgent"

To permanently remove the task:

schtasks.exe /Delete /TN "BackgroundAgent" /F

This does not delete the application itself or its configuration files.

11. Final reboot verification

After configuration is complete, reboot Windows normally.

After startup, verify the process:

Get-Process agent

Then verify the scheduled task:

schtasks.exe /Query /TN "BackgroundAgent" /V /FO LIST

A healthy persistent configuration should show approximately:

Status:                               Running
Scheduled Task State:                 Enabled
Run As User:                          SYSTEM
Schedule Type:                        At system start up
Stop Task If Runs X Hours and X Mins: Disabled

At that point, the program no longer depends on opening a terminal or logging into a desktop account.

12. Resulting execution model

The resulting startup sequence is approximately:

Windows boots
    ↓
Task Scheduler starts
    ↓
wait 30 seconds
    ↓
launch agent.exe as SYSTEM
    ↓
load configuration
    ↓
continue running in Session 0

This produces behavior similar to a lightweight Windows service without requiring the application itself to implement the Windows Service API.

Conclusion

For command-line applications that need to remain active continuously, Windows Task Scheduler is a practical alternative to installing additional service-management software.

The key configuration points are:

Trigger:          At system startup
Account:          SYSTEM
Privilege:        Highest
Startup delay:    30 seconds
Execution limit:  Disabled
User login:       Not required

Once these settings are in place, a normal command-line program can operate as a persistent Windows background component while remaining easy to inspect, stop, disable, or remove using standard Windows tools.

Leave a Reply

Your email address will not be published. Required fields are marked *