Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

Commented Unassigned: Access Denied Exception when creating simple planned task [12370]

$
0
0
Hello,

I'm creating a simple planned task like this:

```
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "AutoRestartTest";

LogonTrigger mainTrigger = new LogonTrigger();
mainTrigger.ExecutionTimeLimit = TimeSpan.FromDays(30);
mainTrigger.Repetition.Interval = TimeSpan.FromMinutes(1);

td.Triggers.Add(mainTrigger);

td.Actions.Add(new ExecAction(@"C:\example.exe", null, null));

ts.RootFolder.RegisterTaskDefinition(@"TestTask1", td);
}
```

And I am getting this exception at the last line of the code:

Access Denied (Exception of HRESULT: 0x80070005 (E_ACCESSDENIED))

I have created a Manifest-File to take care of this option being set to this:

```
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
```

Please help!
What am I doing wrong?

Greetings,

Tom

ps. I dont know why code inserted in the codeblock remains black/white.
Comments: ** Comment from web user: Ravior **

Okay I found out that it had to do with the fact that I'm defining a LogonTrigger without setting its "UserId" property. When I set it to the currently logged on user, it entered the task to the task scheduler and didnt throw the exception.

I guess it has something to do with when the UserId isnt defined, in the Task-scheduler you would choose the option "at the logon of every user" which surely depends on user rights.


Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>