How can I set the "Run whether user is logged on or not" option?
I would like use this to ensure that a scheduled task run 5min aftet at startup.
String strPath;
BootTrigger cBootTrigger;
cBootTrigger = new BootTrigger();
cBootTrigger.Delay = new TimeSpan(0, 5, 0);
strPath = "c:\\MyAPP.exe";
using (TaskService ts = new TaskService())
{
TaskFolder tf = ts.RootFolder;
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "MyAppAtBoot";
td.Principal.LogonType = TaskLogonType.InteractiveToken;
// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(cBootTrigger);
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction(strPath, null, null));
// Register the task in the root folder
try
{
ts.RootFolder.RegisterTaskDefinition(@"MyAppAtBoot", td);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}