How do I set Task
or Thread
privileges ?
I ask because I use Task Scheduler Managed Wrapper and when I call it in another thread (that apparently has lower privileges) I get exception.
I saw this SO question, but didn't manage to use it successfully (Thread.CurrentPrincipal.Identity as WindowsIdentity
is null)
Edit:
This is how I start the thread:
await Task.Factory.StartNew(() => {
/*...*/
}, cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
Edit 2:
These are the exception's details:
COMException: Interface not registered (Exception from HRESULT: 0x80040155)
at Microsoft.Win32.TaskScheduler.V2Interop.IRegisteredTask.get_Definition()
at Microsoft.Win32.TaskScheduler.Task.get_Definition()
at TCM.TaskShedulerStartUp.Update() in c:\...\TaskShedulerStartUp.cs:line 61