1

I'am trying to modify a scheduled task, manually created in Windows task scheduler, using C# application

enter image description here

using the following code:

rootFolder.RegisterTaskDefinition(taskEdit.Name, 
            taskDefinition, 6, null, null, _TASK_LOGON_TYPE.TASK_LOGON_NONE, null);

My code works perfectly when I perform this operation in the principal task scheduler folder. But when I try to modify a task in a subfolder I got the error

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

If try to use username and password instead of null as follow:

rootFolder.RegisterTaskDefinition(taskEdit.Name, taskDefinition, 6, "username", "pwd", 
                           _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD, null);

I got the error below:

(48,4):UserId:

Any ideas? Really Thanks!

4

2 回答 2

1

One solution for your issue is you can use Task Scheduler Managed Wrapper, download at https://taskscheduler.codeplex.com/.

This is a very powerful wrapper that can work with Windows Task Scheduler and can handle the issue "Access is denied" also.

于 2016-09-22T09:02:19.623 回答
0

Finally I got the solution, at least for develop time...I have to run Visual Studio as administrator. In this way I can modify tasks in whatever folder.

于 2016-09-08T16:39:18.393 回答