Hi guys,
I am trying to create a schedule task at the installation time on a Windows 7 32bits, but there is something wrong because it returns me an exception "LogonType". Another thing, I want to create a schedule to run every day at 9h morning.
Can you help me out on this one? What is missing?!
This is the code that I am using:
I am trying to create a schedule task at the installation time on a Windows 7 32bits, but there is something wrong because it returns me an exception "LogonType". Another thing, I want to create a schedule to run every day at 9h morning.
Can you help me out on this one? What is missing?!
This is the code that I am using:
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Daily trigger";
td.Principal.LogonType = TaskLogonType.InteractiveToken;
DailyTrigger dt = new DailyTrigger();
dt.Repetition.Duration = TimeSpan.FromHours(9); // is this ok to run every day at 9h?????
td.Triggers.Add(dt);
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("c:\\Launcher.exe"));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Scheduler", td);
}