2016年5月13日金曜日

Microsoft.Win32.TaskScheduler マイテンプレ

Microsoft.Win32.TaskScheduler.dll Task Scheduler Managed Wrapper の自分用テンプレートです:

private void bREG_Click(object sender, EventArgs e) {
    TaskDefinition td = TaskService.Instance.NewTask();
    td.Actions.Add(
        Path.Combine(Application.StartupPath, "xxx.exe"),
        " \"" + tbH.Text + "." + tbD.Text + "\" \"" + tbP.Text + "\" "
        );
    int mins = Convert.ToInt32(this.mins.Value);
    DailyTrigger t = new DailyTrigger(1);
    t.StartBoundary = new DateTime(DateTime.Now.Year, 1, 1);
    t.Repetition.Duration = TimeSpan.FromDays(1);
    t.Repetition.Interval = TimeSpan.FromMinutes(mins);
    td.Triggers.Add(t);
    td.Principal.UserId = (Environment.OSVersion.Version < new Version(5, 3)) ? "SYSTEM" : "LOCAL SERVICE";
    //td.Settings.RunOnlyIfLoggedOn = false;
    TaskService.Instance.RootFolder.RegisterTaskDefinition("xxx", td);
    MessageBox.Show(this, "設定しました。"
        , Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}


0 件のコメント:

コメントを投稿