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:
Nothing has worked... I'm wondering if others have faced this issue with Windows Server 2019, and how they got scheduled tasks to run?
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"
toTask version="1.3"
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
to<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
Or add string<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
after string <Settings>
if string<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
is absent.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.
This will allow the scheduled task to run at the highest level with Administrative rights.
That's all.
I hope this helps
User contributions licensed under CC BY-SA 3.0