Windows 10 Windows task scheduler not running automatically at schedule time.

  • Thread starter Thread starter RonakIQ
  • Start date Start date
R

RonakIQ

Hi


I am creating windows task scheduler using windows forms app in c# and library i used is Microsoft.Win32.TaskScheduler.


Task is getting created successfully and account to execute this task is NT AUTHORITY\SYSTEM.


But, task does not run automatically at scheduled timings. Once scheduled timing is passed next run is updated with new time but last run still shows 11/30/1991 12:00:00 AM which is default timing. Also, Last run result shows "The task has not run yet(0x41303)".


Operating system i am using is windows 10 but this windows forms app will be installed on OS Windows XP and later versions.


Below is the code snippet i am using to create scheduler.


Why is scheduler not running automatically. How to troubleshoot the issue?




var ts = new TaskService();
var td = ts.NewTask();
td.
RegistrationInfo.Author = "My company";
td.
RegistrationInfo.Description = "Runs test application";
var trigger = new WeeklyTrigger { StartBoundary = startDate, DaysOfWeek = daysOfWeek, Enabled = enabled };
trigger.
Repetition.Interval = TimeSpan.FromSeconds(((minutes == 0) ? 60 : minutes) * 60);
td.
Triggers.Add(trigger);
var action = new ExecAction(Assembly.GetExecutingAssembly().Location, null, null);
if (filePath != string.Empty && File.Exists(filePath))
{
action =
new ExecAction(filePath);
}
action.
Arguments = "AutoRun";
td.
Actions.Add(action);
ts.
RootFolder.RegisterTaskDefinition(TaskName, td);




Continue reading...
 
Back
Top