This project has moved. For the latest updates, please go here.

getting security information for a task

Topics: Examples
Feb 6, 2015 at 5:14 PM
I am trying to list all the tasks and the associated account that is running the task. I got the list of tasks just fine.
I am trying to obtain the userid of the context the task runs under is eluding me?
any suggestions?
I see Task.GetAccessControl() but I am not able to obtain the owner or userid?
Coordinator
Feb 7, 2015 at 10:47 PM
I think you are looking for one of two things: 1) The user account under which the task was created - in which case use Task.Definition.RegistrationInfo.Author or 2) The user account under which the task runs - in which case use Task.Definition.Principal.ToString() (which will pull either UserId or GroupId property based on logon type).
Marked as answer by dahall on 2/7/2015 at 3:48 PM
Feb 8, 2015 at 2:06 PM
Thanks, I spent a better part of the day looking in the tasksecurity class. LOL. I went and looked at your source code for the interface and was able to identify the task.definition class.
Just getting familiar with the wrapper.

I would like to extend a big thanks for this work.
Now on to figuring out how to change the password for the Task.

I know peeps like to see code, that is how we learn. Simple stuff so far, but just in case someone else runs into this.
   class Program
    {
        static void Main()
        {

            using (TaskService ts = new TaskService("wtxwt0017"))
            {
                EnumTaskFolders(ts.RootFolder);

            }



        }

        public static void EnumTaskFolders(TaskFolder taskFolder)
        {
            foreach (Task task in taskFolder.Tasks)
            {
                listTasks(task);

            }
            Console.ReadLine();
        }

        public static void listTasks(Task t)
        {
            
            string userid = t.Definition.Principal.ToString();       

            Console.WriteLine(string.Format("task name = {0} , userid - {1}", t.Name, userid));
        }

       
    }
    
}
Coordinator
Feb 9, 2015 at 2:38 PM
The only way to change the password for a task is to re-register the task.