i want to create a schedule task in root folder . this is my code
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "notepad";
td.Principal.UserId = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
td.Principal.LogonType = TaskLogonType.InteractiveToken;
td.Triggers.Add(new LogonTrigger() { Enabled = true });
td.Principal.RunLevel = TaskRunLevel.Highest;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
td.Actions.Add(new ExecAction("notepad.exe", null, null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Browser", td);
}
The application gives "access denied", even though my user is administrator!
Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
User contributions licensed under CC BY-SA 3.0