Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

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

$
0
0
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);
             
            }

Viewing all articles
Browse latest Browse all 2206

Trending Articles