Create Task in C #


I have a doubt that I'm doing a console that creates a task scheduled in windows, when I put the windows credentials I create the task without problems, the problem is that I need to create that scheduled task without credentials, some idea of how to do it?

here the code:

  using (ScheduledTasks Tareas = new ScheduledTasks())

                    TaskScheduler.Task tarea = Tareas.CreateTask("Reprogramando");

                    tarea.ApplicationName = @"C:\Users\"+userName+"\Desktop\Programa.exe";
                    tarea.Comment = "Tarea reprogramada del programa semanal";
                    // Acá deseo que se cree sin la SetAccountInfo 
                    tarea.SetAccountInformation("userName", "Password");
                    // limitar la duración de la tarea programada
                    tarea.MaxRunTime = new TimeSpan(0, 15, 0);
                    tarea.Creator = "Ac";
                    // prioridad de la tarea
                    tarea.Priority = System.Diagnostics.ProcessPriorityClass.Normal;

                    tarea.Triggers.Add(new RunOnceTrigger(task.AddHours(1)));
asked by Joel Baez 22.11.2018 в 16:02

1 answer


Let's analyze the documentation of the library

A New Task Scheduler Class Library for .NET

You have just the question that refers to how to assign credentials.


Must I have an account and password for a task?


A scheduled task must be given to a specific account in which to run or it may be set to run in the local system account. The local system account is a pseudo-account used by many of the standard services. It has broad access to the local system, but it can not always interact with the user directly and it has not network privileges. To set a task to run in the local system account, the client must be running in that account or in an administrator account.


If the task will need to interact with the user, you need to set up a specific user account and the task will only interact with that user. If your client runs in different accounts depending on who is using it, you can have it schedule tasks without actually knowing the user's password. To this, you set a specific task flag, RunOnlyIfLoggedOn and give the user name and a null password.

Whether or not to indicate the user and password has to see if the application you are going to execute will have interaction with the user.

You could indicate the property RunOnlyIfLoggedOn then define the name of a user but with the password in null

answered by 23.11.2018 / 05:29