### BootTrigger Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_BootTrigger.htm This example demonstrates how to create a BootTrigger that fires 5 minutes after the system starts. Note that the Delay property is specific to V2 triggers. ```APIDOC ## Example ```csharp // Create trigger that fires 5 minutes after the system starts. BootTrigger bt = new BootTrigger(); bt.Delay = TimeSpan.FromMinutes(5); // V2 only ``` ``` -------------------------------- ### TaskSettings.AllowDemandStart Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskSettings_AllowDemandStart.htm Gets or sets a Boolean value that indicates that the task can be started by using either the Run command or the Context menu. ```APIDOC ## TaskSettings.AllowDemandStart Property ### Description Gets or sets a Boolean value that indicates that the task can be started by using either the Run command or the Context menu. ### Syntax ```csharp [DefaultValueAttribute(true)] [XmlElementAttribute("AllowStartOnDemand")] [XmlIgnoreAttribute] public bool AllowDemandStart { get; set; } ``` ### Namespace Microsoft.Win32.TaskScheduler ### Assembly Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) ``` -------------------------------- ### RunEx Example with Parameters Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/M_Microsoft_Win32_TaskScheduler_Task_RunEx.htm This example demonstrates how to run a task with specific flags, targeting a different user, and providing a parameter. It ignores any predefined constraints for the task execution. ```C# var runningTask = myTaskInstance.RunEx(TaskRunFlags.IgnoreConstraints, 0, "DOMAIN\\User", "info"); Console.Write(string.Format("Running task's current action is {0}.", runningTask.CurrentAction)); ``` -------------------------------- ### SelectionStart Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Properties_T_Microsoft_Win32_TaskScheduler_CustomComboBox.htm Gets or sets the starting index of text selected in the combo box. ```APIDOC ## Property SelectionStart ### Description Gets or sets the starting index of text selected in the combo box. ### Type System.Int32 ``` -------------------------------- ### RunEx Example without Parameters Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/M_Microsoft_Win32_TaskScheduler_Task_RunEx.htm This is a basic example of calling RunEx without any specific parameters, using default flags and user. ```C# RunEx(0, 0, "MyUserName") ``` -------------------------------- ### SessionStateChangeTrigger Examples Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_SessionStateChangeTrigger.htm Examples of how to create and configure SessionStateChangeTrigger instances for various session state changes. ```APIDOC ## SessionStateChangeTrigger Usage Examples ### Description These examples demonstrate how to instantiate and configure `SessionStateChangeTrigger` objects for different session state change events. ### Code Examples **Console Connect Trigger:** ```csharp new SessionStateChangeTrigger { StateChange = TaskSessionStateChangeType.ConsoleConnect, UserId = "joe" }; ``` **Console Disconnect Trigger:** ```csharp new SessionStateChangeTrigger { StateChange = TaskSessionStateChangeType.ConsoleDisconnect }; ``` **Remote Connect Trigger:** ```csharp new SessionStateChangeTrigger { StateChange = TaskSessionStateChangeType.RemoteConnect }; ``` **Remote Disconnect Trigger:** ```csharp new SessionStateChangeTrigger { StateChange = TaskSessionStateChangeType.RemoteDisconnect }; ``` **Session Lock Trigger:** ```csharp new SessionStateChangeTrigger { StateChange = TaskSessionStateChangeType.SessionLock, UserId = "joe" }; ``` **Session Unlock Trigger:** ```csharp new SessionStateChangeTrigger { StateChange = TaskSessionStateChangeType.SessionUnlock }; ``` ### Remarks The `SessionStateChangeTrigger` activates upon six distinct system events: local or remote connection/disconnection, and session locking/unlocking. ``` -------------------------------- ### Create a Time Trigger Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/N_Microsoft_Win32_TaskScheduler.htm This example shows how to create a time trigger for a task. It sets the start boundary for the task execution. ```C# TimeTrigger timeTrigger = new TimeTrigger(); timeTrigger.StartBoundary = "2023-01-01T12:00:00"; timeTrigger.Enabled = true; ``` -------------------------------- ### TaskCollection Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_TaskCollection.htm Example demonstrating how to use TaskCollection to retrieve and process tasks from the root folder. ```APIDOC ## Example Usage ### Description This C# example shows how to use the TaskCollection to find tasks in the root folder that start with a specific prefix. ### Code ```csharp public class Program { bool RootFolderHasTask(string taskName) { if (TaskService.Instance.RootFolder.Tasks.Count > 0) { return TaskService.Instance.RootFolder.Tasks.Exists(taskName); } return false; } TaskCollection GetRootTasksStartingWith(string value) { var pattern = $"^{Regex.Escape(value)}.*$"; return TaskService.Instance.RootFolder.GetTasks(new Regex(pattern)); } public static void Main() { foreach (var task in GetRootTasksStartingWith("MyCo")) if (RootFolderHasTask(task.Name)) Console.WriteLine(task.Name); } } ``` ### Remarks This example highlights the use of `TaskService.Instance.RootFolder.Tasks` and the `GetTasks` method with a regular expression pattern. ``` -------------------------------- ### IdleTrigger Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_IdleTrigger.htm This example demonstrates how to create and initialize an IdleTrigger. ```APIDOC ## Example C# ```csharp IdleTrigger it = new IdleTrigger(); ``` ``` -------------------------------- ### Start Method Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Methods_T_Microsoft_Win32_TaskScheduler_ITaskHandler.htm Called to start the COM handler. This method must be implemented by the handler. ```APIDOC ## Start ### Description Called to start the COM handler. This method must be implemented by the handler. ### Method [Method Signature Placeholder - actual signature not provided in source] ### Parameters [No parameters explicitly documented for this method in the source] ### Return Value [No return value explicitly documented for this method in the source] ``` -------------------------------- ### TaskEventLog Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_TaskEventLog.htm Example demonstrating how to create a TaskEventLog instance, configure enumeration, and iterate through task events. ```APIDOC ## Example ```csharp // Create a log instance for the Maint task in the root directory TaskEventLog log = new TaskEventLog(@"\\Maint", // Specify the event id(s) you want to enumerate new int[] { 141 /* TaskDeleted */, 201 /* ActionSuccess */ }, // Specify the start date of the events to enumerate. Here, we look at the last week. DateTime.Now.AddDays(-7)); // Tell the enumerator to expose events 'newest first' log.EnumerateInReverse = false; // Enumerate the events foreach (TaskEvent ev in log) { // TaskEvents can interpret event ids into a well known, readable, enumerated type if (ev.StandardEventId == StandardTaskEventId.TaskDeleted) output.WriteLine($" Task '{ev.TaskPath}' was deleted"); // TaskEvent exposes a number of properties regarding the event else if (ev.EventId == 201) output.WriteLine($" Completed action '{ev.DataValues["ActionName"]}', ({ev.DataValues["ResultCode"]}) at {ev.TimeCreated.Value}."); } ``` ``` -------------------------------- ### ComHandlerAction Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_ComHandlerAction.htm This example demonstrates how to create and configure a ComHandlerAction. ```APIDOC ## ComHandlerAction Example ### Description This example demonstrates how to create and configure a ComHandlerAction. ### Code ```csharp ComHandlerAction comAction = new ComHandlerAction(new Guid("{CE7D4428-8A77-4c5d-8A13-5CAB5D1EC734}")); comAction.Data = "Something specific the COM object needs to execute. This can be left unassigned as well."; ``` ``` -------------------------------- ### JavaScript to Construct Request Example Link Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_CustomComboBox_SelectionStart.htm This JavaScript code dynamically constructs a URL for a 'Request Example' link. It appends query parameters to the base URL, including the page title and a descriptive body, to facilitate user requests for new examples. ```javascript var HT_requestExampleLink = document.getElementById("HT_RequestExampleLink"); if(HT_requestExampleLink.href.substring(0, 4).toLowerCase() == "http") HT_requestExampleLink.href += "?title="; else HT_requestExampleLink.href += "?subject=Task%20Scheduler%20Managed%20Class%20Library: "; HT_requestExampleLink.href += "Add an Example for " + encodeURIComponent(document.title) + "&body=" + encodeURIComponent("Please add an example for " + document.title + ".%0D%0DTODO (optional): Describe a specific " + "scenario you would like to see addressed.%0D%0DHelp Topic: " + window.location.href).replace(/%250D/g, "%0D"); ``` -------------------------------- ### EmailAction Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_EmailAction.htm This example demonstrates how to create and configure an EmailAction object. ```APIDOC ## EmailAction Example ### Description This example demonstrates how to create and configure an EmailAction object. ### Code ```csharp EmailAction ea = new EmailAction("Task fired", "sender@email.com", "recipient@email.com", "You just got a message", "smtp.company.com"); ea.Bcc = "alternate@email.com"; ea.HeaderFields.Add("reply-to", "dh@mail.com"); ea.Priority = System.Net.Mail.MailPriority.High; // All attachment paths are checked to ensure there is an existing file ea.Attachments = new object[] { "localpath\\ondiskfile.txt" }; ``` ``` -------------------------------- ### Starting(Int32, Int32, Int32, Int32, Int32, Int32) Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Methods_T_Microsoft_Win32_TaskScheduler_Fluent_TriggerBuilder.htm Specifies a date and time on which a trigger will start. ```APIDOC ## Starting(Int32, Int32, Int32, Int32, Int32, Int32) ### Description Specifies a date and time on which a trigger will start. ### Method Method Signature ### Parameters * **year** (Int32) - Description not available in source. * **month** (Int32) - Description not available in source. * **day** (Int32) - Description not available in source. * **hours** (Int32) - Description not available in source. * **minutes** (Int32) - Description not available in source. * **seconds** (Int32) - Description not available in source. ``` -------------------------------- ### Starting(String) Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Methods_T_Microsoft_Win32_TaskScheduler_Fluent_TriggerBuilder.htm Specifies a date and time on which a trigger will start using a string representation. ```APIDOC ## Starting(String) ### Description Specifies a date and time on which a trigger will start. ### Method Method Signature ### Parameters * **dateTime** (String) - Description not available in source. ``` -------------------------------- ### RegistrationTrigger Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_RegistrationTrigger.htm This example demonstrates how to create a RegistrationTrigger that fires a task 5 minutes after its registration. ```APIDOC ## RegistrationTrigger Example ### Description Creates a trigger that will fire the task 5 minutes after its registered. ### Code ```csharp // Create a trigger that will fire the task 5 minutes after its registered RegistrationTrigger rTrigger = new RegistrationTrigger(); rTrigger.Delay = TimeSpan.FromMinutes(5); ``` ``` -------------------------------- ### Create a Weekly Trigger Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/N_Microsoft_Win32_TaskScheduler.htm This example demonstrates how to create a weekly trigger for a task. It specifies the start date, time, and the days of the week on which the task should run. ```C# WeeklyTrigger weeklyTrigger = new WeeklyTrigger(); weeklyTrigger.StartBoundary = "2023-01-01T12:00:00"; weeklyTrigger.DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Wednesday | DaysOfTheWeek.Friday; weeklyTrigger.WeeksInterval = 1; weeklyTrigger.Enabled = true; ``` -------------------------------- ### Starting(Int32, Int32, Int32) Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Methods_T_Microsoft_Win32_TaskScheduler_Fluent_TriggerBuilder.htm Specifies a date on which a trigger will start. ```APIDOC ## Starting(Int32, Int32, Int32) ### Description Specifies a date on which a trigger will start. ### Method Method Signature ### Parameters * **year** (Int32) - Description not available in source. * **month** (Int32) - Description not available in source. * **day** (Int32) - Description not available in source. ``` -------------------------------- ### TaskEventWatcher Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/N_Microsoft_Win32_TaskScheduler.htm This example shows how to set up a watcher for system events related to tasks. It utilizes the EventRecorded event. Only available for Task Scheduler 2.0 on Windows Vista or Windows Server 2003 and later. ```C# TaskEventWatcher taskEventWatcher = new TaskEventWatcher(); // Configure event filters and subscribe to the EventRecorded event ``` -------------------------------- ### DailyTrigger Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_DailyTrigger.htm Example demonstrating how to create a DailyTrigger that runs every other day with a random delay. ```APIDOC ## DailyTrigger Example ### Description This example shows how to create a trigger that runs every other day and will start randomly between 10 a.m. and 12 p.m. ### Code ```csharp DailyTrigger dt = new DailyTrigger(); dt.StartBoundary = DateTime.Today + TimeSpan.FromHours(10); dt.DaysInterval = 2; dt.RandomDelay = TimeSpan.FromHours(2); // V2 only ``` ``` -------------------------------- ### RepetitionPattern Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_RepetitionPattern.htm Example demonstrating how to create and configure a RepetitionPattern for a TimeTrigger. ```APIDOC ## Example C# ```csharp // Create a time trigger with a repetition var tt = new TimeTrigger(new DateTime().Now.AddHours(1)); // Set the time in between each repetition of the task after it starts to 30 minutes. tt.Repetition.Interval = TimeSpan.FromMinutes(30); // Default is TimeSpan.Zero (or never) // Set the time the task will repeat to 1 day. tt.Repetition.Duration = TimeSpan.FromDays(1); // Default is TimeSpan.Zero (or never) // Set the task to end even if running when the duration is over tt.Repetition.StopAtDurationEnd = true; // Default is false; // Do the same as above with a constructor tt = new TimeTrigger(new DateTime().Now.AddHours(1)) { Repetition = new RepetitionPattern(TimeSpan.FromMinutes(30), TimeSpan.FromDays(1), true) }; ``` ``` -------------------------------- ### LogonTrigger.UserId Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_LogonTrigger_UserId.htm Gets or sets the identifier of the user. For example, "MyDomain\MyName" or for a local account, "Administrator". This property can be in one of the following formats: User name or SID: The task is started when the user logs on to the computer. NULL: The task is started when any user logs on to the computer. ```APIDOC ## LogonTrigger.UserId Property ### Description Gets or sets the identifier of the user. For example, "MyDomain\MyName" or for a local account, "Administrator". This property can be in one of the following formats: * User name or SID: The task is started when the user logs on to the computer. * NULL: The task is started when any user logs on to the computer. ### Property Value [String](https://learn.microsoft.com/dotnet/api/system.string) ### Syntax C# ```csharp [DefaultValueAttribute(null)] [XmlIgnoreAttribute] public string UserId { get; set; } ``` ### Remarks If you want a task to be triggered when any member of a group logs on to the computer rather than when a specific user logs on, then do not assign a value to the LogonTrigger.UserId property. Instead, create a logon trigger with an empty LogonTrigger.UserId property and assign a value to the principal for the task using the Principal.GroupId property. ``` -------------------------------- ### Registering a Task Definition Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/M_Microsoft_Win32_TaskScheduler_TaskFolder_RegisterTaskDefinition.htm This example demonstrates how to create a new task definition, configure its triggers and actions, and then register it in the root folder. It shows the creation of a weekly trigger and an action to launch Notepad. ```C# // Create a new task definition for the local machine and assign properties TaskDefinition td = TaskService.Instance.NewTask(); td.RegistrationInfo.Description = "Does something"; // Add a trigger that, starting tomorrow, will fire every other week on Monday and Saturday td.Triggers.Add(new WeeklyTrigger(DaysOfTheWeek.Monday | DaysOfTheWeek.Saturday, 2)); // Create an action that will launch Notepad whenever the trigger fires td.Actions.Add("notepad.exe", "c:\\test.log"); // Register the task in the root folder of the local machine using the current user and the S4U logon type TaskService.Instance.RootFolder.RegisterTaskDefinition("Test", td); ``` -------------------------------- ### TaskRunTimesDialog.StartDate Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskRunTimesDialog_StartDate.htm Gets or sets the start date. ```APIDOC ## TaskRunTimesDialog.StartDate Property ### Description Gets or sets the start date. ### Syntax C# ```csharp public DateTime StartDate { get; set; } ``` ### Property Value [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime) - The start date. ``` -------------------------------- ### Daily Trigger Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/N_Microsoft_Win32_TaskScheduler.htm Represents a trigger that starts a task based on a daily schedule. This example shows how to create a daily trigger. ```C# DailyTrigger dailyTrigger = new DailyTrigger(); dailyTrigger.DaysInterval = 2; dailyTrigger.StartBoundary = DateTime.Today.AddDays(1).AddHours(9); dailyTrigger.Enabled = true; ``` -------------------------------- ### TimeTrigger Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_TimeTrigger.htm Example demonstrating how to create a TimeTrigger that runs at a specific future date and time. ```APIDOC ## Example ```csharp // Create a trigger that runs the last minute of this year TimeTrigger tTrigger = new TimeTrigger(); tTrigger.StartBoundary = new DateTime(DateTime.Today.Year, 12, 31, 23, 59, 0); ``` ``` -------------------------------- ### RunningTask.InstanceGuid Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_RunningTask_InstanceGuid.htm Gets the GUID identifier for this instance of the task. ```APIDOC ## RunningTask.InstanceGuid Property ### Description Gets the GUID identifier for this instance of the task. ### Property Value [Guid](https://learn.microsoft.com/dotnet/api/system.guid) ``` -------------------------------- ### Create and Configure ExecAction Source: https://github.com/dahall/taskscheduler/wiki/ActionSamples Demonstrates creating an ExecAction with parameters and setting its properties. ```C# ExecAction ea1 = new ExecAction("notepad.exe", "file.txt", null); ExecAction ea2 = new ExecAction(); ea2.Path = "notepad.exe"; ea.Arguments = "file2.txt"; ``` -------------------------------- ### TaskEventLog Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/N_Microsoft_Win32_TaskScheduler.htm This example demonstrates how to access the historical event log for a task. It is only available on Windows Vista and later. ```C# TaskEventLog taskEventLog = new TaskEventLog(); // Access event log properties and methods here ``` -------------------------------- ### BeginInit Method Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Methods_T_Microsoft_Win32_TaskScheduler_TaskService.htm Signals the object that initialization is starting. ```APIDOC ## BeginInit ### Description Signals the object that initialization is starting. ### Method Public method ### Endpoint N/A (Class Method) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### StartWhenAvailable Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Properties_T_Microsoft_Win32_TaskScheduler_TaskSettings.htm Gets or sets a Boolean value that indicates that the Task Scheduler will start the task as soon as possible after a scheduled start time is missed. ```APIDOC ## StartWhenAvailable ### Description Gets or sets a Boolean value that indicates that the Task Scheduler will start the task as soon as possible after a scheduled start time is missed. ### Property Type Boolean ``` -------------------------------- ### TaskPrincipal Usage Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_TaskPrincipal.htm Example demonstrating how to set the UserId and LogonType for a TaskPrincipal. ```APIDOC ## Example ```csharp TaskDefinition td = TaskService.Instance.NewTask(); td.Principal.UserId = "SYSTEM"; td.Principal.LogonType = TaskLogonType.ServiceAccount; ``` ``` -------------------------------- ### Example Usage Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_ShowMessageAction.htm Demonstrates how to create and use a ShowMessageAction. ```APIDOC ## Example ```csharp ShowMessageAction msg = new ShowMessageAction("You just got a message!", "SURPRISE"); ``` ``` -------------------------------- ### TaskDefinition.Triggers Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskDefinition_Triggers.htm Gets a collection of triggers that are used to start a task. ```APIDOC ## TaskDefinition.Triggers Property ### Description Gets a collection of triggers that are used to start a task. ### Syntax ```csharp [XmlArrayItemAttribute(ElementName = "BootTrigger", IsNullable = true, Type = typeof(BootTrigger))] [XmlArrayItemAttribute(ElementName = "IdleTrigger", IsNullable = true, Type = typeof(IdleTrigger))] [XmlArrayItemAttribute(ElementName = "LogonTrigger", IsNullable = true, Type = typeof(LogonTrigger))] [XmlArrayItemAttribute(ElementName = "TimeTrigger", IsNullable = true, Type = typeof(TimeTrigger))] [XmlArrayAttribute] public TriggerCollection Triggers { get; } ``` ### Property Value [TriggerCollection](T_Microsoft_Win32_TaskScheduler_TriggerCollection.htm) ``` -------------------------------- ### OnBoot Method Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Methods_T_Microsoft_Win32_TaskScheduler_Fluent_ActionBuilder.htm Adds a trigger that executes at system startup. ```APIDOC ## OnBoot ### Description Adds a trigger that executes at system startup. ### Method (Implicitly called via ActionBuilder) ### Endpoint (Not applicable for SDK methods) ### Parameters (No specific parameters mentioned for this basic trigger) ### Request Example (Not applicable for SDK methods) ### Response (Returns the modified ActionBuilder instance for chaining) ``` -------------------------------- ### TaskRunTimesControl.StartDate Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskRunTimesControl_StartDate.htm Gets or sets the start date. This property is of type DateTime. ```APIDOC ## TaskRunTimesControl.StartDate Property ### Description Gets or sets the start date for a scheduled task. ### Syntax ```csharp public DateTime StartDate { get; set; } ``` ### Property Value [DateTime](https://learn.microsoft.com/dotnet/api/system.datetime) - The start date. ``` -------------------------------- ### WeeklyTrigger Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/N_Microsoft_Win32_TaskScheduler.htm Represents a trigger that starts a task based on a weekly schedule. For example, the task starts at 8:00 A.M. on a specific day of the week every week or every other week. ```APIDOC ## WeeklyTrigger ### Description Represents a trigger that starts a task based on a weekly schedule. For example, the task starts at 8:00 A.M. on a specific day of the week every week or every other week. ### Type Public class ``` -------------------------------- ### LogonTrigger Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_LogonTrigger.htm Demonstrates how to create and configure a LogonTrigger, including setting a delay and specifying a user for V2 triggers. ```APIDOC ## LogonTrigger Usage Example ### Description This example shows how to create a basic logon trigger and a V2-specific logon trigger with a user ID and delay. ### Code ```csharp // Add a general logon trigger LogonTrigger lt1 = new LogonTrigger(); // V2 only: Add a delayed logon trigger for a specific user LogonTrigger lt2 = new LogonTrigger { UserId = "LocalUser" }; lt2.Delay = TimeSpan.FromMinutes(15); ``` ### Remarks - The `UserId` property is specific to V2 triggers. - The `Delay` property allows you to postpone the trigger's activation after the logon event. ``` -------------------------------- ### Delay Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Properties_T_Microsoft_Win32_TaskScheduler_ITriggerDelay.htm Gets or sets a value that indicates the amount of time before the task is started. ```APIDOC ## Delay Property ### Description Gets or sets a value that indicates the amount of time before the task is started. ### Type TimeSpan ### Access Public property ``` -------------------------------- ### BeginInit Method Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Methods_T_Microsoft_Win32_TaskScheduler_TaskRunTimesControl.htm Signals the object that initialization is starting. This method is part of the TaskRunTimesControl class. ```APIDOC ## BeginInit Method ### Description Signals the object that initialization is starting. ### Method Public ### Endpoint N/A (Method Signature) ### Parameters None ### Request Example N/A ### Response N/A ``` -------------------------------- ### ITriggerDelay.Delay Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_ITriggerDelay_Delay.htm Gets or sets a value that indicates the amount of time before the task is started. ```APIDOC ## ITriggerDelay.Delay Property ### Description Gets or sets a value that indicates the amount of time before the task is started. ### Syntax ```csharp TimeSpan Delay { get; set; } ``` ### Property Value [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) - The delay duration. ``` -------------------------------- ### CustomComboBox.SelectionStart Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_CustomComboBox_SelectionStart.htm Gets or sets the starting index of text selected in the combo box. ```APIDOC ## CustomComboBox.SelectionStart Property ### Description Gets or sets the starting index of text selected in the combo box. ### Syntax ```csharp [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)] [BrowsableAttribute(false)] public int SelectionStart { get; set; } ``` ### Namespace Microsoft.Win32.TaskScheduler ### Assembly Microsoft.Win32.TaskSchedulerEditor (in Microsoft.Win32.TaskSchedulerEditor.dll) ``` -------------------------------- ### ITaskHandler.Start Method Parameters Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/M_Microsoft_Win32_TaskScheduler_ITaskHandler_Start.htm Details on the parameters accepted by the ITaskHandler.Start method. ```APIDOC #### Parameters pHandlerServices (Object) - An IUnkown interface that is used to communicate back with the Task Scheduler. data (String) - The arguments that are required by the handler. These arguments are defined in the [Data](P_Microsoft_Win32_TaskScheduler_ComHandlerAction_Data.htm) property of the COM handler action. ``` -------------------------------- ### DisallowStartOnRemoteAppSession Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskSettings_DisallowStartOnRemoteAppSession.htm Gets or sets a value indicating whether the task is allowed to start if it is on a remote session. ```APIDOC ## Property Value [Boolean](https://learn.microsoft.com/dotnet/api/system.boolean) ## Exceptions | Exception | Condition | |---|---| | [NotSupportedPriorToException](T_Microsoft_Win32_TaskScheduler_NotSupportedPriorToException.htm) | Property set for a task on a Task Scheduler version prior to 2.1. | ## See Also ### Reference * [TaskSettings Class](T_Microsoft_Win32_TaskScheduler_TaskSettings.htm) * [Microsoft.Win32.TaskScheduler Namespace](N_Microsoft_Win32_TaskScheduler.htm) ``` -------------------------------- ### DisallowStartIfOnBatteries Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskSettings_DisallowStartIfOnBatteries.htm Gets or sets a value indicating whether the task is allowed to start if the computer is on batteries. ```APIDOC ## Property Value [Boolean](https://learn.microsoft.com/dotnet/api/system.boolean) ## See Also [TaskSettings Class](T_Microsoft_Win32_TaskScheduler_TaskSettings.htm) [Microsoft.Win32.TaskScheduler Namespace](N_Microsoft_Win32_TaskScheduler.htm) ``` -------------------------------- ### Run Task with a Parameter Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/M_Microsoft_Win32_TaskScheduler_Task_Run.htm Demonstrates how to run the current task with a single string parameter. The parameter 'info' is passed, and the output shows the task's current action. ```C# var runningTask = myTaskInstance.Run("info"); Console.Write(string.Format("Running task's current action is {0}.", runningTask.CurrentAction)); ``` -------------------------------- ### RegistrationTrigger.Delay Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_RegistrationTrigger_Delay.htm Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started. ```APIDOC ## RegistrationTrigger.Delay Property ### Description Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started. ### Syntax ```csharp [DefaultValueAttribute(typeof(TimeSpan), "00:00:00")] [XmlIgnoreAttribute] public TimeSpan Delay { get; set; } ``` ### Property Value [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) ### Exceptions - **NotV1SupportedException**: Not supported under Task Scheduler 1.0. ``` -------------------------------- ### LogonTrigger.Delay Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_LogonTrigger_Delay.htm Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started. ```APIDOC ## LogonTrigger.Delay Property ### Description Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started. ### Property Value [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) ### Syntax ```csharp [DefaultValueAttribute(typeof(TimeSpan), "00:00:00")] [XmlIgnoreAttribute] public TimeSpan Delay { get; set; } ``` ### Exceptions - **NotV1SupportedException**: Not supported under Task Scheduler 1.0. ``` -------------------------------- ### Setting up and starting a TaskEventWatcher Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_TaskEventWatcher.htm Demonstrates how to create, configure, and enable a TaskEventWatcher to monitor a specific task folder for events. It includes filtering by task name and event levels, and assigning an event handler. ```C# private TaskEventWatcher watcher; // Create and configure a new task watcher for the task folder private void SetupWatcher(TaskFolder tf) { if (tf != null) { // Set up a watch over the supplied task folder. watcher = new TaskEventWatcher(tf); // Assign a SynchronizingObject to a local UI class to synchronize the events in this thread. watcher.SynchronizingObject = this; // Only watch for tasks that start with my company name watcher.Filter.TaskName = "MyCo*"; // Only watch for task events that are informational watcher.Filter.EventLevels = new int[] { 0 /* StandardEventLevel.LogAlways */, (int)StandardEventLevel.Informational }; // Assign an event handler for when events are recorded watcher.EventRecorded += Watcher_EventRecorded; // Start watching the folder by enabling the watcher watcher.Enabled = true; } } ``` -------------------------------- ### EventTrigger.Delay Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_EventTrigger_Delay.htm Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started. ```APIDOC ## EventTrigger.Delay Property ### Description Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started. ### Property Value [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) ### Syntax C# ```csharp [DefaultValueAttribute(typeof(TimeSpan), "00:00:00")] public TimeSpan Delay { get; set; } ``` ``` -------------------------------- ### BootTrigger.Delay Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_BootTrigger_Delay.htm Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started. ```APIDOC ## BootTrigger.Delay Property ### Description Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started. ### Property Value [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) - The delay time. ### Exceptions - [NotV1SupportedException](T_Microsoft_Win32_TaskScheduler_NotV1SupportedException.htm): Not supported under Task Scheduler 1.0. ### Syntax ```csharp [DefaultValueAttribute(typeof(TimeSpan), "00:00:00")] [XmlIgnoreAttribute] public TimeSpan Delay { get; set; } ``` ``` -------------------------------- ### Create and Register Task Remotely C# Snippet Source: https://github.com/dahall/taskscheduler/blob/master/TaskService/TaskService.md Example demonstrating how to connect to a remote server, define a task with a daily trigger and an executable action, and register it. Ensure you have the necessary credentials and permissions for remote access. ```C# using System; using Microsoft.Win32.TaskScheduler; class Program { static void Main() { // Get the service on the remote machine using (TaskService ts = new TaskService(@"\\RemoteServer", "username", "domain", "password")) { // Create a new task definition and assign properties TaskDefinition td = ts.NewTask(); td.RegistrationInfo.Description = "Does something"; // Create a trigger that will fire the task at this time every other day td.Triggers.Add(new DailyTrigger { DaysInterval = 2 }); // Create an action that will launch Notepad whenever the trigger fires td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null)); // Register the task in the root folder. // (Use the username here to ensure remote registration works.) ts.RootFolder.RegisterTaskDefinition(@"Test", td, TaskCreation.CreateOrUpdate, "username"); } } } ``` -------------------------------- ### Fluent Task Scheduling in C# Source: https://github.com/dahall/taskscheduler/wiki/Examples Illustrates various ways to schedule tasks using the library's fluent API. Examples cover different timing and recurrence options. ```C# TaskService.Instance.Execute("notepad.exe").WithArguments(@"c:\temp\music.txt").Once().Starting(2013, 11, 11, 11, 0, 0).RepeatingEvery(TimeSpan.FromMinutes(5)).AsTask("Test"); ``` ```C# TaskService.Instance.Execute("notepad.exe").Every(2).Days().Starting("12/25/2013 7:00pm").AsTask("Test"); ``` ```C# TaskService.Instance.Execute("notepad.exe").Every(3).Weeks().AsTask("Test"); ``` ```C# TaskService.Instance.Execute("notepad.exe").OnAll(DaysOfTheWeek.Monday).In(WhichWeek.FirstWeek).Of(MonthsOfTheYear.January).AsTask("Test"); ``` ```C# TaskService.Instance.Execute("notepad.exe").InTheMonthOf(MonthsOfTheYear.January).OnTheDays(1, 3, 5).AsTask("Test"); ``` ```C# TaskService.Instance.Execute("notepad.exe").OnBoot().AsTask("Test"); ``` ```C# TaskService.Instance.Execute("notepad.exe").OnIdle().AsTask("Test"); ``` ```C# TaskService.Instance.Execute("notepad.exe").OnStateChange(TaskSessionStateChangeType.ConsoleConnect).AsTask("Test"); ``` ```C# TaskService.Instance.Execute("notepad.exe").AtLogonOf("AMERICAS\\dahall").AsTask("Test"); ``` ```C# TaskService.Instance.Execute("notepad.exe").AtTaskRegistration().AsTask("Test"); ``` ```C# // ** New syntax with Version 2.8.13 ** TaskService.Instance.Execute("notepad").OnIdle().When.ExecutingAtMost(TimeSpan.FromHours(8)).OnlyIfIdle().AsTask("Test"); ``` ```C# TaskService.Instance.Execute("notepad").OnIdle().AsTask("Test", TaskCreation.Create, "dahall@github.com", null, TaskLogonType.S4U); ``` -------------------------------- ### TaskRegistrationInfo.Source Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskRegistrationInfo_Source.htm Gets or sets where the task originated from. For example, a task may originate from a component, service, application, or user. ```APIDOC ## TaskRegistrationInfo.Source Property ### Description Gets or sets where the task originated from. For example, a task may originate from a component, service, application, or user. ### Syntax ```csharp [DefaultValueAttribute(null)] public string Source { get; set; } ``` ### Property Value [String](https://learn.microsoft.com/dotnet/api/system.string) ``` -------------------------------- ### Register a Task with Specific User Credentials and Security (C#) Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/M_Microsoft_Win32_TaskScheduler_TaskFolder_RegisterTaskDefinition_1.htm This example demonstrates registering a task with a specific username and password, along with a custom security descriptor. This is useful for tasks that need to run under a dedicated service account or with specific permissions. The security descriptor string follows the SDDL format. ```C# TaskService.Instance.RootFolder.RegisterTaskDefinition("TaskName", taskDefinition, TaskCreation.CreateOrUpdate, "userDomain\\userName", "userPassword", TaskLogonType.Password, @"O:BAG:DUD:(A;ID;0x1f019f;;;BA)(A;ID;0x1f019f;;;SY)(A;ID;FA;;;BA)(A;;FR;;;BU)"); ``` -------------------------------- ### CustomTrigger.Delay Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_CustomTrigger_Delay.htm Gets or sets a value that indicates the amount of time between the trigger events and when the task is started. This property cannot be set. ```APIDOC ## CustomTrigger.Delay Property ### Description Gets a value that indicates the amount of time between the trigger events and when the task is started. ### Syntax ```csharp public TimeSpan Delay { get; set; } ``` ### Property Value [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) ### Exceptions - **NotImplementedException**: This value cannot be set. ``` -------------------------------- ### Create and Register a Task in C# Source: https://github.com/dahall/taskscheduler/wiki/Home Demonstrates how to create a new task definition, add a weekly trigger with repetition, define an action to run Notepad, and register the task using the Task Scheduler library in C#. ```C# using System; using Microsoft.Win32.TaskScheduler; class Program { static void Main(string[]() args) { // Create a new task definition for the local machine and assign properties TaskDefinition td = TaskService.Instance.NewTask(); td.RegistrationInfo.Description = "Does something"; // Add a trigger that, starting tomorrow, will fire every other week on Monday // and Saturday and repeat every 10 minutes for the following 11 hours WeeklyTrigger wt = new WeeklyTrigger(); wt.StartBoundary = DateTime.Today.AddDays(1); wt.DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Saturday; wt.WeeksInterval = 2; wt.Repetition.Duration = TimeSpan.FromHours(11); wt.Repetition.Interval = TimeSpan.FromMinutes(10); td.Triggers.Add(wt); // Create an action that will launch Notepad whenever the trigger fires td.Actions.Add("notepad.exe", "c:\\test.log"); // Register the task in the root folder of the local machine TaskService.Instance.RootFolder.RegisterTaskDefinition("Test", td); } } ``` -------------------------------- ### NetworkSettings.Id Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_NetworkSettings_Id.htm Gets or sets a GUID value that identifies a network profile. This property is not supported under Task Scheduler 1.0. ```APIDOC ## NetworkSettings.Id Property ### Description Gets or sets a GUID value that identifies a network profile. ### Syntax C# ```csharp [DefaultValueAttribute(typeof(Guid), "00000000-0000-0000-0000-000000000000")] public Guid Id { get; set; } ``` ### Property Value [Guid](https://learn.microsoft.com/dotnet/api/system.guid) ### Exceptions - **NotV1SupportedException**: Not supported under Task Scheduler 1.0. ``` -------------------------------- ### TaskSettings.StartWhenAvailable Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskSettings_StartWhenAvailable.htm Gets or sets a Boolean value that indicates that the Task Scheduler can start the task at any time after its scheduled time has passed. ```APIDOC ## TaskSettings.StartWhenAvailable Property ### Description Gets or sets a Boolean value that indicates that the Task Scheduler can start the task at any time after its scheduled time has passed. ### Syntax ```csharp [DefaultValueAttribute(false)] [XmlIgnoreAttribute] public bool StartWhenAvailable { get; set; } ``` ### Namespace Microsoft.Win32.TaskScheduler ### Assembly Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) ``` -------------------------------- ### ActionBuilder.OnBoot Method Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/M_Microsoft_Win32_TaskScheduler_Fluent_ActionBuilder_OnBoot.htm Adds a trigger to the task that will cause it to execute at system startup. ```APIDOC ## ActionBuilder.OnBoot Method ### Description Adds a trigger that executes at system startup. ### Method Signature ```csharp public TriggerBuilder OnBoot() ``` ### Return Value Returns a TriggerBuilder instance, allowing for further configuration of the trigger. ### See Also - [ActionBuilder Class](T_Microsoft_Win32_TaskScheduler_Fluent_ActionBuilder.htm) - [Microsoft.Win32.TaskScheduler.Fluent Namespace](N_Microsoft_Win32_TaskScheduler_Fluent.htm) ``` -------------------------------- ### Creating an ExecAction Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_ExecAction.htm Instantiate an ExecAction to run an executable with specified arguments. The constructor can take the executable path, arguments, and working directory. ```csharp ExecAction ea1 = new ExecAction("notepad.exe", "file.txt", null); ExecAction ea2 = new ExecAction(); ``` -------------------------------- ### AllowDemandStart Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskSettings_AllowDemandStart.htm Gets or sets a value indicating whether the task can be started on demand. This property is not supported under Task Scheduler 1.0. ```APIDOC ## Property Value [Boolean](https://learn.microsoft.com/dotnet/api/system.boolean) ## Exceptions | Exception | Condition | | ------------------------- | ----------------------------- | | NotV1SupportedException | Not supported under Task Scheduler 1.0. | ``` -------------------------------- ### ExecAction Constructors Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_ExecAction.htm Demonstrates the creation of ExecAction objects using different constructors. ```APIDOC ## ExecAction Constructors ### Description This section shows how to instantiate the `ExecAction` class. ### Code Example ```csharp // Create an ExecAction to run notepad.exe with 'file.txt' as an argument ExecAction ea1 = new ExecAction("notepad.exe", "file.txt", null); // Create an empty ExecAction object ExecAction ea2 = new ExecAction(); ``` ``` -------------------------------- ### SessionStateChangeTrigger.UserId Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_SessionStateChangeTrigger_UserId.htm Gets or sets the user for the Terminal Server session. When a session state change is detected for this user, a task is started. ```APIDOC ## SessionStateChangeTrigger.UserId Property ### Description Gets or sets the user for the Terminal Server session. When a session state change is detected for this user, a task is started. ### Property Value [String](https://learn.microsoft.com/dotnet/api/system.string) ### Syntax ```csharp [DefaultValueAttribute(null)] public string UserId { get; set; } ``` ``` -------------------------------- ### Registering a Task with XML Definition Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/M_Microsoft_Win32_TaskScheduler_TaskFolder_RegisterTask.htm This snippet demonstrates how to define a basic task using an XML string and then register it in the root folder of the local machine using the SYSTEM account specified within the XML. Ensure the XML is correctly formatted and includes all necessary task elements. ```C# // Define a basic task in XML var xml = "" + "" + " " + " " + " S-1-5-18" + " " + " " + " " + " " + " 2017-09-04T14:04:03" + " " + " " + " " + " " + " " + " cmd" + " " + " " + ""; // Register the task in the root folder of the local machine using the SYSTEM account defined in XML TaskService.Instance.RootFolder.RegisterTaskDefinition("Test", xml); ``` -------------------------------- ### SessionStateChangeTrigger.Delay Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_SessionStateChangeTrigger_Delay.htm Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started. The default value is 00:00:00. ```APIDOC ## SessionStateChangeTrigger.Delay Property ### Description Gets or sets a value that indicates the amount of time between when the system is booted and when the task is started. ### Syntax ```csharp [DefaultValueAttribute(typeof(TimeSpan), "00:00:00")] public TimeSpan Delay { get; set; } ``` ### Property Value [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) ### Remarks The default value is 00:00:00. ``` -------------------------------- ### MaintenanceSettings.Period Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_MaintenanceSettings_Period.htm Gets or sets the amount of time the task needs to be started during Automatic maintenance. The minimum value is one minute. ```APIDOC ## MaintenanceSettings.Period Property ### Description Gets or sets the amount of time the task needs to be started during Automatic maintenance. The minimum value is one minute. ### Syntax ```csharp [DefaultValueAttribute(typeof(TimeSpan), "00:00:00")] public TimeSpan Period { get; set; } ``` ### Property Value [TimeSpan](https://learn.microsoft.com/dotnet/api/system.timespan) ### Exceptions - **NotSupportedPriorToException**: Property set for a task on a Task Scheduler version prior to 2.2. ``` -------------------------------- ### Trigger.Repetition Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_Trigger_Repetition.htm Gets or sets a RepetitionPattern instance that indicates how often the task is run and how long the repetition pattern is repeated after the task is started. ```APIDOC ## Trigger.Repetition Property ### Description Gets or sets a [RepetitionPattern](T_Microsoft_Win32_TaskScheduler_RepetitionPattern.htm) instance that indicates how often the task is run and how long the repetition pattern is repeated after the task is started. ### Property Value [RepetitionPattern](T_Microsoft_Win32_TaskScheduler_RepetitionPattern.htm) ### Syntax ```csharp public RepetitionPattern Repetition { get; set; } ``` ``` -------------------------------- ### AllowingStartIfOnBatteries Method Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/M_Microsoft_Win32_TaskScheduler_Fluent_SettingsBuilder_AllowingStartIfOnBatteries.htm This method configures the task to start regardless of whether the computer is running on battery power. ```APIDOC ## AllowingStartIfOnBatteries Method ### Description Indicates that the task will be started even if the computer is running on battery power. ### Method Signature C# public SettingsBuilder AllowingStartIfOnBatteries() ### Return Value [SettingsBuilder](T_Microsoft_Win32_TaskScheduler_Fluent_SettingsBuilder.htm) Returns the current SettingsBuilder instance for fluent chaining. ``` -------------------------------- ### TaskSettings.WakeToRun Property C# Example Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskSettings_WakeToRun.htm This C# code shows how to get or set the WakeToRun property for a TaskSettings object. The default value is false. ```csharp [DefaultValueAttribute(false)] public bool WakeToRun { get; set; } ``` -------------------------------- ### BeginInit Method Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/Methods_T_Microsoft_Win32_TaskScheduler_TaskEventWatcher.htm Signals the object that initialization is starting. This method is part of the initialization process for the TaskEventWatcher. ```APIDOC ## BeginInit Method ### Description Signals the object that initialization is starting. ### Method Public ### Endpoint N/A (Method signature) ### Parameters None ### Request Example N/A ### Response N/A ``` -------------------------------- ### ExecutionTimeLimit Property Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/P_Microsoft_Win32_TaskScheduler_TaskSettings_ExecutionTimeLimit.htm Gets or sets the amount of time that is allowed to complete the task. By default, a task will be stopped 72 hours after it starts to run. ```APIDOC ## ExecutionTimeLimit Property ### Description Gets or sets the amount of time that is allowed to complete the task. By default, a task will be stopped 72 hours after it starts to run. ### Syntax C# ```csharp [DefaultValueAttribute(typeof(TimeSpan), "3")] public TimeSpan ExecutionTimeLimit { get; set; } ``` ### Namespace Microsoft.Win32.TaskScheduler ### Assembly Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) ``` -------------------------------- ### Creating and Configuring an EmailAction Source: https://github.com/dahall/taskscheduler/blob/master/docs/html/T_Microsoft_Win32_TaskScheduler_EmailAction.htm Demonstrates how to create an EmailAction and set various properties like BCC, header fields, priority, and attachments. Ensure all attachment paths point to existing files. ```C# EmailAction ea = new EmailAction("Task fired", "sender@email.com", "recipient@email.com", "You just got a message", "smtp.company.com"); ea.Bcc = "alternate@email.com"; ea.HeaderFields.Add("reply-to", "dh@mail.com"); ea.Priority = System.Net.Mail.MailPriority.High; // All attachement paths are checked to ensure there is an existing file ea.Attachments = new object[] { "localpath\\ondiskfile.txt" }; ```