Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

New Post: IIS integration?

$
0
0
Ok so it is working, I post it there in case that somebody has the same problem
using (TaskService ts = new TaskService())
{
    // Create a new task definition and assign properties
    TaskDefinition td = ts.NewTask();
    td.RegistrationInfo.Description = "Does something";

    //Setting to run as Local Service whether the user is logged in or not
    td.Principal.LogonType = TaskLogonType.ServiceAccount;
    td.Principal.UserId = "LocalService";

    // 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
    try { ts.RootFolder.RegisterTaskDefinition(@"Test", td, TaskCreation.CreateOrUpdate, "LocalService", null, TaskLogonType.ServiceAccount); }
    catch (COMException ex) { Marshal.ThrowExceptionForHR(ex.ErrorCode); }

    // Remove the task we just created
    ts.RootFolder.DeleteTask(@"Test");
}

Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>