C# プログラムを使用して、タスク スケジューラで次のオプションを設定しようとしています。
1. In settings tab of Task scheduler, check the box "If the task fails, restart every 1 minute"
2. In General tab of Task scheduler, under security options, set it to "BigDataService" for "When running the task, use the following user account" and provide its password.
私の現在のコードは次のようになります。
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
TimeTrigger trigger = new TimeTrigger();
var startTime = TimeSpan.Parse(section1["ScheduledTime"]);
trigger.StartBoundary = DateTime.Today + startTime;
trigger.Repetition.Interval = TimeSpan.FromDays(1);
trigger.StartBoundary = DateTime.Now;
td.Principal.RunLevel = TaskRunLevel.Highest;
trigger.Id = "Data";
trigger.Repetition.Interval = TimeSpan.FromDays(1);
td.Triggers.Add(trigger);
td.Actions.Add(new ExecAction(@"DataUpload.exe", argument, null));
var foldername = ts.GetFolder(@"\Bigdata");
Console.WriteLine(foldername.Path);
foldername.RegisterTaskDefinition(section1["JobName"], td);
}
New Cod (RegisterTaskDefinition で正常に動作しますが、RepetitionInterval 行を追加すると、BigData フォルダーにタスクが作成されません。
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
TimeTrigger trigger = new TimeTrigger();
var startTime = TimeSpan.Parse(section1["ScheduledTime"]);
trigger.StartBoundary = DateTime.Today + startTime;
trigger.Repetition.Interval = TimeSpan.FromDays(1);
trigger.StartBoundary = DateTime.Now;
td.Principal.RunLevel = TaskRunLevel.Highest;
trigger.Id = "Data";
trigger.Repetition.Interval = TimeSpan.FromDays(1);
td.Triggers.Add(trigger);
td.Actions.Add(new ExecAction(@"DataUpload.exe", argument, null));
var foldername = ts.GetFolder(@"\Bigdata");
Console.WriteLine(foldername.Path);
foldername.RegisterTaskDefinition(section1["JobName"], td, TaskCreation.CreateOrUpdate,"Bigdataservice", "password");
}