This is my code for creating a task:
private TaskDefinition CreateTask()
TaskDefinition td = ts.NewTask();
td.Data = "";
td.Principal.UserId = "Panodil\\Bjarni";
td.Principal.LogonType = TaskLogonType.Password;
td.RegistrationInfo.Author = "Bjarni";
td.RegistrationInfo.Description = "";
td.RegistrationInfo.Documentation = "";
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.Enabled = true;
td.Settings.ExecutionTimeLimit = TimeSpan.FromHours(2);
td.Settings.Hidden = false;
td.Settings.WakeToRun = true;
td.Settings.RunOnlyIfLoggedOn = true;
td.Actions.Add(new ExecAction(@"D:\Dev\iWakeUp\iWakeUpRunner.exe", @"", @"D:\Dev\iWakeUp"));
And then I call this function to save it
private void SaveTask(TaskDefinition td)
Task t = taskFolder.RegisterTaskDefinition("!Alarm", td, TaskCreation.CreateOrUpdate, "Bjarni", "qwdqwd", TaskLogonType.Password, null);
However, no matter if I set Settings.RunOnlyIfLoggedOn to true or false, the task is always saved like this:
This has the side effect that everything I run does not appear on my screen. And I also do not have access to certain functionality that I need.
Is there any way to actually modify this setting? (the one in the red box in the picture above)
Seems to me that RunOnlyIfLoggedOn is the obvious answer, but so far no luck with that.
Found the solution, I have to use an InteractiveToken.
Might want to add an assert on the set property for td.Settings.RunOnlyIfLoggedOn if the task is in v2 mode (because the description says it's v1 only)
But great job anyway! Love the library! Although at start I spent a lot of trime trying to modify existing tasks, but found out that just overwriting them was easier ^^
Apr 30, 2009 at 6:15 PM
Thanks. I have added an exception to that property as you suggested in release 1.3.