How to Configure Windows Task Scheduler to Run Interactive Desktop Applications with UI Automation


2 views

Windows Task Scheduler typically runs tasks in a non-interactive session (Session 0 isolation), which prevents applications from accessing the desktop for UI automation. This becomes problematic when you need scheduled tasks to perform actions like mouse movements or keyboard input.

To successfully run UI-automating EXEs via Task Scheduler, you'll need:

  • Windows 10/11 Pro/Enterprise (Home edition lacks proper Group Policy controls)
  • Administrative privileges on the target machine
  • The "Run only when user is logged on" option selected

Here's the proper way to configure such a task using PowerShell:

# Create a scheduled task that can interact with desktop
$action = New-ScheduledTaskAction -Execute "C:\\Path\\To\\YourApp.exe"
$trigger = New-ScheduledTaskTrigger -Daily -At "3am"
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -RunOnlyIfNetworkAvailable
$principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\\SYSTEM" -LogonType Interactive -RunLevel Highest

Register-ScheduledTask -TaskName "InteractiveDesktopTask" 
    -Action $action 
    -Trigger $trigger 
    -Settings $settings 
    -Principal $principal

For older Windows versions (prior to 1809), you may need this registry tweak:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"AllowMultipleTSSessions"=dword:00000001

For complex UI automation scenarios, consider:

  1. Configure autologin via control userpasswords2
  2. Place your executable in the Startup folder
  3. Use Task Scheduler to reboot the machine at desired times

If your automation still fails, check:

  • Ensure no screensaver/lock is active during execution
  • Verify the task is configured with "Run whether user is logged on or not" unchecked
  • Test with a simple script first (like Notepad automation)

Warning: Interactive scheduled tasks create security risks:

  • Never store plaintext passwords in scripts
  • Consider using Windows Credential Manager
  • Restrict physical access to the machine

When attempting to schedule GUI automation tasks on Windows, many developers encounter the "Session 0 Isolation" security feature introduced since Windows Vista. This prevents scheduled tasks from interacting with the user's desktop by default, which breaks automation scripts requiring mouse/keyboard interaction.

For your daily automation task that needs to:

  • Run a specific executable
  • Perform GUI automation (mouse/keyboard actions)
  • Execute in an interactive desktop session

The solution requires proper configuration of both the scheduled task and the executing environment.

Here's how to properly set up the scheduled task:

# PowerShell command to create the task
$action = New-ScheduledTaskAction -Execute "C:\Path\To\Your\Automation.exe"
$trigger = New-ScheduledTaskTrigger -Daily -At "3am"
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
$principal = New-ScheduledTaskPrincipal -UserId "YOURDOMAIN\username" -LogonType Interactive -RunLevel Highest
Register-ScheduledTask -TaskName "DailyGUI Automation" -Action $action -Trigger $trigger -Settings $settings -Principal $principal
  1. Create Basic Task in Task Scheduler
  2. Set trigger to "Daily"
  3. Action: "Start a program" (point to your EXE)
  4. In the General tab:
    • Check "Run only when user is logged on"
    • Check "Run with highest privileges"
  5. In the Conditions tab:
    • Uncheck "Start the task only if the computer is on AC power"

Important notes for successful implementation:

  • The task must run under a user account that will be logged in
  • For remote access scenarios, ensure the session remains active (use tools like AutoLogon or screen-connect solutions)
  • For Windows services, consider using the "Interactive Services Detection" service

If your automation needs to run when no user is logged in:

# This requires a more complex setup using the Win32 API
# Sample C# code to create a desktop for the service
[DllImport("kernel32.dll")]
static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice, IntPtr pDevmode, int dwFlags, uint dwDesiredAccess, IntPtr lpsa);

// Then use SetThreadDesktop to attach to the created desktop
// Note: This requires careful error handling and cleanup

After setting up your task:

  1. Run the task manually first to verify it works interactively
  2. Check the task's history in Task Scheduler for errors
  3. If automation fails, try running the EXE directly from the target user session

Be aware that running interactive tasks with high privileges:

  • Creates potential security vulnerabilities
  • Should only be done on dedicated automation machines
  • Requires proper user account management (dedicated automation account recommended)