Windows Scheduler: Error details: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
To whom it may concern,
I have used a "TaskHelper" in my Lightswitch App that assist with the Scheduling of Tasks via the Windows Scheduler.
Everything works fine on my Local Machine.
When I deploy my app and I try to Schedule a task via my App I receive the following error:
"Error details: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
I make use of the following Code:
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = TaskName; //Variable Containing the Name of the Task
td.RegistrationInfo.Author = User; //Variable Containing the Current User Name
td.RegistrationInfo.Date = DateTime.Now;
td.Principal.UserId = "SYSTEM";
td.Principal.LogonType = TaskLogonType.ServiceAccount;
The rest of the Task Details is done later in my program, but the problem area is the above Code.
I have tried the following already:
- Ensured that ASPNET, SYSTEM as well as My own credentials has all the Rights in the C:\Windows\System32\Tasks Folder
- Added ASPNET, SYSTEM as well as My own credentials to the DCOMCNFG(Even Everyone)
- Tried different Task Logon Types
- Change Authentical From Integrated to my own credentials in IIS (As a test)
- Everything works on my Local Machine using all the different Scenarios mentioned above. The task is scheduled and executes fine via my app on my local machine.
When I schedule the Task Directly in the Scheduler, with the My User Credentials, Everything works fine. I also Scheduled The task manually and selected SYSTEM as the "Execute As" User. This worked fine
The App is a Browser based app. I make use of Integrated Security (I did use my own credentials in all the tests mentioned above).
The server that I try to run this app on is MS Server 2008 Service Pack 2.
I use the following command to create the actual task:
ts.GetFolder("Folder\\Subfolder").RegisterTaskDefinition(TaskName, td); //These folders already exists and they work file on my Local Machine. I Also tried without the actual folders (Directly in the root, with the same result)
Any Assistance will be appreciated.
Kind Regards,