How to set unset Do not store password. The task will only have access to local computer resources.

Topics: Examples, Setup
May 11, 2015 at 11:38 AM
Edited May 11, 2015 at 11:46 AM
Trying to create a task. And i need to uncheck the
check box Do not store password. The task will only have access to local computer resources.
which is always checked for me. Here is the code
            // Get the service on the local machine
            using (TaskService ts = new TaskService())
            {
                // Create a new task definition and assign properties)
                TaskDefinition td = ts.NewTask();

                td.Principal.RunLevel = TaskRunLevel.Highest;
                td.Principal.LogonType=TaskLogonType.ServiceAccount;
                 td.RegistrationInfo.Description = "MyTask";

                // Create a trigger that will fire the task at this time every other day
                var dailytrigger = new DailyTrigger { DaysInterval = 1 };
                var timespan = new TimeSpan(0, 0, 5, 0);
                dailytrigger.SetRepetition(timespan, TimeSpan.Zero);
                td.Triggers.Add(dailytrigger);
                td.Settings.Compatibility = TaskCompatibility.V2_1;

                var commandParam = GetPowershellParams();

                td.Actions.Add(new ExecAction("Powershell", commandParam, null));



                // Register the task in the root folder
                ts.RootFolder.RegisterTaskDefinition(@"My Task", td, TaskCreation.CreateOrUpdate, username,
                    password);
             
            }
May 11, 2015 at 12:01 PM
use TaskLogonType.Password
Marked as answer by mokchhya on 5/11/2015 at 5:02 AM