4

I would like to set the "Configure for" setting in Task Scheduler to "Windows 7".

Current C# code:

 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);
    td.Triggers.Add(trigger);  
    td.Actions.Add(new ExecAction(@"Data.exe", argument, null));
    var foldername = ts.GetFolder(@"\Bigdata");
    Console.WriteLine(foldername.Path);                                
    foldername.RegisterTaskDefinition(section1["JobName"], td, TaskCreation.CreateOrUpdate, "service@geotab.local", "traincloudCubel!ne");
  }

Any help would be appreciated !!

enter image description here

user3447653
  • 3,968
  • 12
  • 58
  • 100

1 Answers1

6

td.Settings.Compatibility should map to that field.

See the xmldoc on the enum for what each version maps to in the dropdown.

/// <summary>Defines what versions of Task Scheduler or the AT command that the task is compatible with.</summary>
public enum TaskCompatibility
{
    /// <summary>The task is compatible with the AT command.</summary>
    AT,
    /// <summary>The task is compatible with Task Scheduler 1.0 (Windows Server™ 2003, Windows® XP, or Windows® 2000).</summary>
    V1,
    /// <summary>The task is compatible with Task Scheduler 2.0 (Windows Vista™, Windows Server™ 2008).</summary>
    V2,
    /// <summary>The task is compatible with Task Scheduler 2.1 (Windows® 7, Windows Server™ 2008 R2).</summary>
    V2_1,
    /// <summary>The task is compatible with Task Scheduler 2.2 (Windows® 8.x, Windows Server™ 2012).</summary>
    V2_2,
    /// <summary>The task is compatible with Task Scheduler 2.3 (Windows® 10, Windows Server™ 2016).</summary>
    V2_3,
}
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
  • I used td.Settings.Compatibility.Equals("Windows 8.1") to set the Configure for to "Windows 8.1". But still it does not do anything. Wondering whether I am missing something. – user3447653 Jul 07 '16 at 13:04
  • The property is a enum, the correct way would be `td.Settings.Compatibility == TaskCompatibility.V2_2`, look at the code I posted above, `V2_2` maps to "Windows® 8.x, Windows Server™ 2012". – Scott Chamberlain Jul 07 '16 at 13:07
  • setting for run task as soon as possible after a scheduled start is missed c#?? – dilipkumar1007 Apr 06 '17 at 11:19