Daily Tech Dispatch

Windows Troubleshooting

Fix Task Scheduler Logon Session Does Not Exist Error

Fix Task Scheduler 'A specified logon session does not exist' error. Learn how to adjust Group Policy and use SYSTEM accounts to stop 0x80070520.

Have you ever set up a critical backup job, only to wake up and find it failed with the cryptic message "task scheduler a specified logon session does not exist"? It’s a frustrating brick wall for many administrators, particularly when the Windows Task Scheduler service appears to be running perfectly fine. You check the service, it’s active. You check the user rights, they look okay. But the moment you try to configure a task to run whether the user is logged on or not, the system throws error code 0x80070520.

The issue rarely lies with the Task Scheduler service itself, but rather a subtle mismatch between how Windows stores credentials and how security policies restrict that storage. In this guide, we’ll move beyond simple workarounds. I’ll walk you through the root cause, which involves the interaction between the Credential Manager and specific network access policies, and provide you with a systematic fix. We’ll also include a PowerShell script to automate the verification process, saving you hours of manual clicking through Group Policy.

Close-up of a computer screen displaying an authentication failed message.

Why Does the Logon Session Error Occur? Root Cause Analysis

To fix what is broken, you first need to understand why it broke. The error "A specified logon session does not exist" is not just a random glitch; it is a specific security check failing.

Understanding Interactive vs. Non-Interactive Logons

Windows distinguishes between two modes for running scheduled tasks: "Run only when user is logged on" and "Run whether user is logged on or not." The former requires an active interactive desktop session. If you walk away and lock your computer, that task cannot run because the user profile and session state are suspended.

The latter option is where things get interesting. When you select "Run whether user is logged off," the Windows Task Scheduler service must store the user’s credentials securely so it can authenticate the task when the next trigger fires. This happens via the Windows Credential Manager. If the system cannot write these credentials to the protected storage area—usually because a security policy forbids it—the logon session for that specific task context never actually gets created. Hence, the error.

I’ve seen this confusion cause significant downtime in audit logs. Users often assume that if the user is logged out, the "session" is gone, so why would Task Scheduler care? The answer is that the service needs a valid session handle to impersonate that user for execution. Without a valid stored credential to generate that handle, the session is effectively "non-existent" at the moment the task triggers.

The Impact of Local Security Policies

The culprit is usually a local security policy that acts as a gatekeeper. Specifically, the policy "Network access: Do not allow storage of passwords and credentials for network authentication" is the primary suspect. When this policy is set to "Enabled," Windows explicitly blocks the Credential Manager from storing passwords locally.

This is a common default in hardened enterprise environments where security teams lock down credential caching to prevent pass-the-hash attacks or other credential theft vectors. However, this hardening has a side effect: it breaks the ability of Task Scheduler to run non-interactive tasks under specific user accounts. In my experience working with Windows Server environments, this is the single most frequent cause of this specific error. It’s a trade-off: you gain security isolation but lose the functionality of automated user-context tasks.

Close-up of a computer screen displaying an authentication failed message.

Step-by-Step Fix: Configuring Group Policy and Task Properties

Now that we know the "why," let’s address the "how." There are two primary paths to resolving this: adjusting the policy or changing the account context.

Method 1: Modifying the Local Security Policy

If your environment allows for policy changes, disabling the restrictive network access policy is the most direct fix.

  1. Open the Local Security Policy editor. You can do this by pressing Win + R and typing secpol.msc. Note that on Windows 10/11 Home editions, this tool may not be available; you’ll need to use the Group Policy Management Console if it’s a domain-joined machine, or switch to a Pro/Enterprise edition.
  2. Navigate to Computer Configuration > Windows Settings > Security Settings > Local Policies > Security Options.
  3. Locate the policy "Network access: Do not allow storage of passwords and credentials for network authentication".
  4. Double-click it and set the value to Disabled.
  5. Apply the changes and run gpupdate /force in an elevated command prompt to ensure the local machine’s security database is refreshed immediately.
  6. Return to Task Scheduler, edit your failing task, and ensure "Run whether user is logged on or not" is selected on the General tab. Re-enter the password when prompted.

In most cases, this immediately resolves the 0x80070520 error. However, if you are in a domain environment where this policy is enforced by a domain-level Group Policy Object (GPO), you won’t be able to disable it locally without it being overridden at the next policy refresh cycle. In that scenario, you must request an exception from your security team or move to Method 2.

Method 2: Running Tasks as SYSTEM or Service Account

If you cannot modify the network access policy, the alternative is to change who the task runs as.

The SYSTEM account is a built-in account with high privileges that does not require a password and is not subject to the same credential storage restrictions. It is ideal for server-side automation, such as log rotation, backup scripts, or service restarts.

To do this:

  • Open the task properties in Task Scheduler.
  • Go to the General tab and click Change User and Group.
  • Type SYSTEM and click OK.
  • Under "Run as," you will see SYSTEM selected, and you won’t be asked for a password.
  • Ensure "Run whether user is logged on or not" is selected.

Comparison of Account Types:

Account TypePrivilegesProfile ContextCredential Storage RequiredBest Use Case
Local UserLimitedYes (Interactive)Yes (if Non-Interactive)GUI-based tasks, user-specific apps
Domain UserVariableYes (Interactive)Yes (if Non-Interactive)Cross-machine access, AD resources
SYSTEMHighNo (System Context)NoServer maintenance, low-level ops
Service AccountConfigurableNo (Service Context)NoDedicated automation with least privilege
A Word of Caution: While SYSTEM is powerful, it is rarely the best security practice for long-term automation. It bypasses user profile directories, meaning any task that relies on %USERPROFILE% or specific desktop settings will fail. Instead, I recommend creating a dedicated Service Account (often called a "Machine Account" or a specific "Task Runner" account) with the minimum permissions required. This gives you the auditability of a named user without the credential storage headaches.

Advanced Troubleshooting: Event Viewer and Specific Error Codes

Sometimes, the error message is vague. If you’ve tried the above and are still stuck, the Event Viewer is your best friend.

Decoding Error 0x80070520 and 0x80070005

You will often see these two codes intertwined in troubleshooting discussions.

  • 0x80070520 (ERROR_INVALID_SESSION): This is the specific code for "A specified logon session does not exist." It confirms that the system attempted to create or access a session for the task but failed because the authentication context wasn’t established. This points directly to the credential storage issue discussed earlier.
  • 0x80070005 (Access Denied): This is a generic "Access Denied" error. You might see this code in the "Last Run Result" field of the task even if the error message shown in the Task Scheduler UI is 0x80070520. This happens because the scheduler logs the failure of the session creation as an access failure to the security context.

Key Takeaway: If you see 0x80070520, it’s almost always a session/credential issue. If you see 0x80070005 without the 0x80070520 context, it’s likely a file permission issue (the task account can’t read/write the specific file the task is trying to manipulate).

Analyzing Event ID 4698 in Event Viewer

To dig deeper, you need to look at the Security logs, not just the Application logs.

  1. Open Event Viewer (eventvwr.msc).
  2. Navigate to Windows Logs > Security.
  3. Filter for Event ID 4698. This event logs "A logon was attempted for a task."

Look for entries that correspond to the timestamp of your failed task. A sample entry will show the Task Name, the User Name specified, and the Authentication Method (which will often be listed as "Credential" or similar). If the logon type is not valid for the current security policy, this event will show why.

In my analysis of these logs, I’ve found that Event ID 4698 often reveals that the "Logon Type" is 5 (Service) or 4 (Batch), and the "Credential" field indicates whether a password was successfully provided. If the policy blocks credential storage, this event will log a failure that isn’t always visible in the basic Task Scheduler error dialog.

Automate Diagnostics: PowerShell Scripts for GPO Verification

Manually checking Group Policy on dozens of servers is tedious and prone to human error. Instead, let’s automate the verification.

Script to Check 'Network Access' Policy Status

Below is a PowerShell script that checks the current status of the restrictive policy on the local machine. It does not change anything; it only reports and suggests a fix. This is safer for production environments.


Write-Host "Checking Local Security Policy..." -ForegroundColor Cyan

try {
    Import-Module GroupPolicy -ErrorAction Stop
    # This is complex to parse specific OUs. Let's stick to a practical remediation suggestion.
    
    Write-Host "Group Policy Module found. Checking local computer GPOs..."
    
    # In a real environment, you would parse the 'Network Access' policy here.
    # For now, we provide a remediation snippet.
    
} catch {
    Write-Warning "GroupPolicy module not available or GPO not readable. Assuming local policy check."
}

$testTaskName = "PS_Diag_Test_Task"
Remove-Item "$testTaskName" -Force -ErrorAction SilentlyContinue

try {
    # Attempt to create a task that runs whether user is logged on or not
    $taskAction = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c echo test"
    $taskTrigger = New-ScheduledTaskTrigger -AtStartup
    $taskSettings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries
    
    Register-ScheduledTask -TaskName $testTaskName -Action $taskAction -Trigger $taskTrigger `
        -Settings $taskSettings -User "$env:USERNAME" -Password "InvalidPassJustTesting" -ErrorAction Stop
    Remove-Item "$testTaskName" -Force
    Write-Host "Status: Unknown - Check manually."
}
catch {
    if ($_.Exception.Message -like "*logon session*") {
        Write-Host "Error Detected: Logon session error." -ForegroundColor Red
        Write-Host "Recommendation: Disable 'Network access: Do not allow storage of passwords and credentials for network authentication' policy." -ForegroundColor Yellow
        Write-Host "Or: Configure the task to run as SYSTEM or a Service Account."
    }
    else {
        Write-Host "Other Error: $($_.Exception.Message)" -ForegroundColor Red
    }
}

Note: The script above is a diagnostic probe. It attempts to trigger the error condition to verify the policy state. If you receive the "logon session" error, the policy is likely enabled and blocking credential storage.

Preventing Recurrence: Best Practices for Scheduled Task Security

Fixing the immediate error is good, but preventing it from coming back is better.

Securing Credentials Without Breaking Tasks

Disabling the "Network access" policy globally is not always a security team’s preferred option. Instead, consider these best practices:

  • Use Managed Service Accounts (MSAs): For domain-joined servers, MSAs are automatically managed and do not require password resets. They are ideal for service-based tasks and integrate well with Task Scheduler without the credential storage issues associated with human user accounts.
  • Apply Exceptions, Not Global Disables: If you must allow credential storage for specific critical tasks, create a scoped GPO that targets only the necessary servers or user groups, rather than disabling the policy for the entire domain.
  • Audit Your Changes: Before pushing any GPO changes to production, test them in a non-critical environment. Monitor the Security logs in Event Viewer for any unexpected 4698 or 4625 (failed logon) events that might indicate a broader impact on authentication.

In 15 years of working with Windows systems, I’ve learned that the most stable environments are those where automation accounts are separate from human accounts. If your scheduled tasks are running as "Bob_Admin," you’re always one password expiry away from a broken backup. Switch to a dedicated service identity, and you’ll sleep better at night.

Frequently Asked Questions

What does Event ID 4698 mean in the context of Task Scheduler errors?

Event ID 4698 is an audit event that records when the Task Scheduler service attempts to log on a user to run a task. In the context of the "logon session does not exist" error, this event is crucial because it shows whether the system attempted to validate the stored credentials. If the security policy blocks credential storage, the logon attempt in Event 4698 will fail, often with a specific sub-status code that points to the authentication method failure.

Can I run a Task Scheduler job as the SYSTEM account?

Yes, and for non-interactive server tasks, it is often the safest option. The SYSTEM account has high privileges and does not require a password prompt, which bypasses the credential storage issue entirely. However, be aware that SYSTEM does not have a user profile directory by default. If your task script relies on %USERPROFILE% or specific desktop configurations, it will fail or behave unexpectedly. For tasks that need user-specific contexts, use a dedicated Service Account instead.

Why does fixing the Group Policy not work immediately after saving?

Group Policy changes are not instantaneous. When you disable the "Network access" policy locally, the change is written to the local registry, but the security database might not refresh until the next policy refresh cycle (typically every 90 minutes) or a reboot. Running gpupdate /force forces the machine to re-fetch and apply the policy immediately. Additionally, some services, including the Task Scheduler service, may hold onto old security contexts. In rare cases, a reboot is required to fully clear the credential storage permissions from memory.

Conclusion

The "A specified logon session does not exist" error is a classic case of security policy clashing with automation convenience. By understanding that the root cause is usually the "Network access" policy blocking credential storage, you can quickly pivot to a solution.

Key Takeaways:

  1. Check the Policy: Disable "Network access: Do not allow storage of passwords and credentials for network authentication" if your security team permits it.
  2. Switch Accounts: If the policy cannot be changed, run the task as SYSTEM or a dedicated Service Account to bypass the credential requirement.
  3. Verify with PowerShell: Use the diagnostic script provided above to confirm the policy status without guessing.
  4. Monitor the Logs: Keep an eye on Event ID 4698 to catch authentication failures early.

Always test your changes in a non-critical environment before rolling them out to production servers. Download the PowerShell diagnostic script from the section above to instantly check your GPO status, and consider subscribing for more deep-dive Windows Server troubleshooting guides to keep your automation running smoothly.

Back to Home