This project has moved and is read-only. For the latest updates, please go here.

cannot creating a task without running app as admin

Topics: Errors
May 7, 2015 at 5:57 AM
when trying to create tasks I get access denied unless the program is stated as admin. the user is a local admin on the system, the task is being created on the same system, and the task is to be run as a different user. below is the gist of the code, please let me know
using (TaskService ts = new TaskService())
           TimeTrigger start = new TimeTrigger { StartBoundary = dateTime1.Value };
            TaskDefinition td = ts.NewTask();
            td.Principal.RunLevel = TaskRunLevel.Highest;
            td.Settings.Compatibility = TaskCompatibility.V2_2;
            td.Actions.Add(new ExecAction(Environment.GetCommandLineArgs()[0], cmd, null));
            ts.RootFolder.RegisterTaskDefinition("Task Name", td, TaskCreation.Create, username, password, TaskLogonType.Password);
any ideas?
May 10, 2015 at 8:29 PM
The code calling the TaskService constructor must be running as Administrator to avoid UAC blocks. The security rights of the TaskService instance will determine if the RegisterTaskDefinition method can be called. Registering a task as a specific user instruct that task to run as that user.
Marked as answer by dahall on 9/1/2015 at 10:00 AM