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
Or add string
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
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.
I hope this helps
User contributions licensed under CC BY-SA 3.0