RegisterTask fails on windows 10 (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)


I am running the example given on https://taskscheduler.codeplex.com/ on my localPC.
 using (TaskService ts = new TaskService())
     // Create a new task definition and assign properties
     TaskDefinition td = ts.NewTask();
     td.RegistrationInfo.Description = "Does something";

     // Create a trigger that will fire the task at this time every other day
     td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });

     // Create an action that will launch Notepad whenever the trigger fires
     td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));

     // Register the task in the root folder
     ts.RootFolder.RegisterTaskDefinition(@"Test", td);
I see this Behaviour:
  • This fails on Windows 10 PC.
  • This works on WIndows 7 PC.
  • This works on Windows 10 PC if I start the application as "Run as administrator"
Error Details:__
Microsoft.Win32.TaskScheduler - Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTaskDefinition
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition

I want to run the application without using "Run as Administrator" on windows 10. Can you suggest a fix.

file attachments

Closed Thu at 3:30 PM by dahall


Colecas wrote Jun 27 at 11:22 AM

Same error in Windows Server 2016, version 1607.
I'm working with the last release version of the task scheduled managed wrapper, 2.5.27

dahall wrote Jun 27 at 2:19 PM

From the documentation (http://taskscheduler.codeplex.com/wikipage?title=TaskSecurity):
  • By default, to schedule a task, you must be a member of the Administrators, Backup Operators, or Server Operators group on the local computer.
  • By default, when creating a scheduled task, you cannot enter a user who belongs to a group that has more rights than the group you belong to.
  • By default, a user who creates a task can read, update, delete, and run the task.
  • Members of the Administrators group or the SYSTEM account can read, update, delete, and run any tasks. Members of the Users group, the LocalService account, and the NetworkService account can only read, update, delete, and run the tasks that they have created.

wrote Jun 29 at 9:48 AM

Colecas wrote Jun 29 at 9:48 AM

The task is trying to be registered with an account who is member of the Administrator group.

Colecas wrote Jun 29 at 12:03 PM

See attachment, the user used is TestUser4.

dahall wrote Jul 1 at 4:32 PM

Please try running the troubleshooter @ https://taskscheduler.codeplex.com/releases/view/622295

wrote Jul 3 at 2:40 PM

Colecas wrote Jul 3 at 2:40 PM

You can see the errors showed by the Troubleshooter, running with my user TestUser4 who belongs to the Administrator group. And also has full rights in the C:\Windows\Task folder. I don't understand why the troubleshooter is showing that.
Do you have an idea?

Colecas wrote Jul 3 at 2:41 PM

Please see the attachment TroubleShooter.jpg

dahall wrote Jul 4 at 8:42 PM

Do you happen to know if, when run, the Troubleshooter either was run as Administrator or if they clicked the option to run as administrator in the first page of the wizard? Failing to do either could product the results you're seeing. Also, unless you are specifically calling the TaskService constructor with all 5 parameters and setting the last parameter to true (forceV1), then only the V2 related items in the Troubleshooter are relevant.

Also, is that happening with other accounts on other Windows 10 installations?

Colecas wrote Jul 6 at 7:54 AM

The Troubleshooter was running with an administrator account. I have tested to click the option to run as administrator in the first page of the wizard, and the troubleshooter advise me to give the right "Log on as a batch job". This right is enabled by default for the Administrator group, to which my account belongs.

The behaviour is reproduced in other Windows 10 installations? Just, to be clear, I am logged as administrator in the machine (with a domain account), but not with the default administrator.

wrote Jul 6 at 10:49 PM

dahall wrote Jul 6 at 10:49 PM

Let's try this: I have uploaded a zip file with a small app that can run small code snippets against the Task Scheduler library (TestTaskLibConsole.zip). On an offending system, extract the files to a folder and then run TestTaskLibConsole.exe in the same account as your prior tests withing running the application as Administrator. Also in the zip file is a file "testcode.cs" that contains the snippet you have reported as failing. You can open this file from the console program or paste its contents into the console window and then click the Run button. If it fails, please send me a snapshot of the window.

I have tried this snippet in the console on Win 10 (1703 & 1607) and Server 2016 (1607) without any failures. I am running in a domain account that is a member of the local machine's Administrators group. In the zip file is a "capture.png" image that has a clip of the output from Win 10.

Hopefully this will help us narrow your problem.

Colecas wrote Jul 10 at 3:14 PM

It works. What have you changed?

wrote Jul 10 at 3:24 PM

Colecas wrote Jul 10 at 3:24 PM

It doesn't work if I add running the task with highest privileges.
As you can see in the attachment "highest.jpg".

dahall wrote Jul 12 at 10:43 AM

So it appears this is a security feature of the Windows base library and not this wrapper. Let me know if I can close this issue now.

Colecas wrote Jul 12 at 12:55 PM

Yes, thanks for your help Dahall.

wrote Thu at 3:30 PM