TaskScheduler: "Access is Denied" (0x80070005) when running scheduled tasks on Windows Server 2019

2

I just set up a new Windows Server 2019 instance, and am trying to run tasks (C# console apps) through Windows Task Scheduler. I've set it up to log in as a certain windows user, which has "Administrators" permission. However, when I try to run the task (either on a schedule or by logging in and running it on-demand) it gives the error:

"Access is Denied" with the error code 0x80070005. Things I've tried so far:

  • Double-checked that the user account's password is correct.
  • Double-checked that they're in the Administrators group.
  • Tried using a different admin user account.
  • Installed all windows updates.
  • Rebooted the server.
  • Given all permissions to the directory where the job executable resides.
  • Checked the box to run the job with "highest privileges".

Nothing has worked... I'm wondering if others have faced this issue with Windows Server 2019, and how they got scheduled tasks to run?

powershell
windows-server
taskscheduler
windows-task-scheduler
windows-server-2019
asked on Stack Overflow Jan 29, 2019 by Justin • edited Mar 14, 2021 by Promise Preston

2 Answers

0

In Windows 7 SP1 I encountered with same problem. Nothing worked.
I found workaround:
1) In Task Scheduler export task (to .xml).
2) Delete task in Task Scheduler.
3) Edit .xml-file:
3.1) In second string replace

Task version="1.2"
to
Task version="1.3"

3.2) Replace string
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
to
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
Or add string
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
after string
  <Settings>
if string
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
is absent.
4) Import .xml-file to Task Scheduler.
Now task runs.
I found this workaround when I noticed that built-in Windows tasks run normally.

answered on Stack Overflow Aug 22, 2019 by Mish
0

I had a similar challenge when trying to create a scheduled task on Powershell to copy files to a mapped drive.

Below was my scheduled task commands:

$TaskName = "FileSync"
$Description = "This task will run periodically to sync .fin files from a specified source directory to a specified destination directory"
$ScriptPath = "C:\Users\my_userDesktop\file_sync.ps1"
$UserAccount = "COMP1\my_user"
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-ExecutionPolicy Bypass -File $ScriptPath"
$Principal = New-ScheduledTaskPrincipal -UserID $UserAccount -LogonType ServiceAccount -RunLevel Highest
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 1) -RepetitionDuration ([System.TimeSpan]::MaxValue)
Register-ScheduledTask -TaskName $TaskName -Action $Action -Description $Description -Trigger $Trigger -Principal $Principal

However, I was getting the error below when the command runs:

Register-ScheduledTask : Access is denied.
At line:1 char:1
+ Register-ScheduledTask -TaskName $TaskName -Action $Action -Description $Descrip ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-Schedul
   edTask], CimException
    + FullyQualifiedErrorId : HRESULT 0x80070005,Register-ScheduledTask

Here's how I fixed it:

The cause of the issue was the -RunLevel Highest command in:

$Principal = New-ScheduledTaskPrincipal -UserID $UserAccount -LogonType ServiceAccount -RunLevel Highest

-RunLevel Highest registers a scheduled task that runs under logged-in members of the Administrators user group that has the highest privileges.

This means that when you set the -RunLevel to Highest it requires that you schedule the Powershell job as an Administrator, that is, you must Run Powershell as an Administrator to schedule the job instead of just starting/running Powershell ad a normal user to schedule the job.

enter image description here

This will allow the scheduled task to run at the highest level with Administrative rights.

That's all.

I hope this helps

answered on Stack Overflow Mar 14, 2021 by Promise Preston

User contributions licensed under CC BY-SA 3.0