I've an error related with Sheduled tasks in windows server 2003.
I'm using Microsoft.Win32.TaskSheduler.dll to add a bat file to the Sheduled tasks.
When I add the file manually, there is no problem but when i try to add the file via code(I'm using C#).
Here is the code i'm using:
TaskService ts = new TaskService();
TimeTrigger tt = new TimeTrigger();
tt.StartBoundary = DateTime.Now;
tt.Enabled = true;
tt.Repetition.Duration = TimeSpan.FromMinutes(5);
tt.Repetition.Interval = TimeSpan.FromMinutes(1);
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.Triggers.Add(tt);
string exec_action = "c:\folder\file.bat"
td.Actions.Add(
new ExecAction(exec_action,
null, null
));
string taskName = "taskName";
ts.RootFolder.RegisterTaskDefinition(taskName, td
,TaskCreation.CreateOrUpdate,
null, null,
TaskLogonType.InteractiveToken,
null);
In the string exec_action, if i put there "notepad.exe", the task "fires" and the note pad opens, but if i put there the bat file, i see the cmd console opening and closing very fast but nothing happens.
If i run the bat file with "double click" it also works well.
I don't know what i'm missing here, if someone can help me, i would be thankful!
I'm using Microsoft.Win32.TaskSheduler.dll to add a bat file to the Sheduled tasks.
When I add the file manually, there is no problem but when i try to add the file via code(I'm using C#).
Here is the code i'm using:
TaskService ts = new TaskService();
TimeTrigger tt = new TimeTrigger();
tt.StartBoundary = DateTime.Now;
tt.Enabled = true;
tt.Repetition.Duration = TimeSpan.FromMinutes(5);
tt.Repetition.Interval = TimeSpan.FromMinutes(1);
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.Triggers.Add(tt);
string exec_action = "c:\folder\file.bat"
td.Actions.Add(
new ExecAction(exec_action,
null, null
));
string taskName = "taskName";
ts.RootFolder.RegisterTaskDefinition(taskName, td
,TaskCreation.CreateOrUpdate,
null, null,
TaskLogonType.InteractiveToken,
null);
In the string exec_action, if i put there "notepad.exe", the task "fires" and the note pad opens, but if i put there the bat file, i see the cmd console opening and closing very fast but nothing happens.
If i run the bat file with "double click" it also works well.
I don't know what i'm missing here, if someone can help me, i would be thankful!