You need to enumerate the Triggers
for each task
and either do something with the task, store it for later, or store the name in a list of your filtered Task
object names. Your selection process is to check if Trigger
is either a OnLogonTrigger
or a OnSystemStartTrigger
then you can select that task into your final List.
e.g.
List<string> startupAndLogonTasks = new List<string>();
foreach (string taskName in st.GetTaskNames()) {
using (Task task = st.OpenTask(taskName)) {
if (task != null) {
foreach (Trigger tr in task.Triggers) {
if (tr is OnSystemStartTrigger || tr is OnLogonTrigger) {
// Do something, such as log the name, or store the task for later
startupAndLogonTasks.Add(task.Name);
// break out and move to the next task
break;
}
}
}
}
}
Of course, if you want tasks that only have the logon or startup type, then also check you only have 1 trigger in the Triggers
collection.