0

In my C# application, I am using ITask Task Scheduler interface to create the Task into Task Scheduler. I can able to create the task but I am facing problem in assigning Application name. Everytime I create a task "Start a program" (Application Name) is not enclosed in double quotes even if I append the double quotes from code and set Application name using ITask::SetApplicationName() method its not working.

The real problem arise when I try to edit the Task from Task Scheduler. The actual path and arguments are messed up (Please refer the image). "G:\Some Name WithSpace\Build\Some.exe" this is my actual application name.

enter image description here

Note : If I create same from MS Task Scheduler it appends with double quotes.

Davy
  • 134
  • 5
  • Are you escaping the quotes in the original string? The MS code is parsing your command line to a reasonable expectation of "C:\App Args". Have your tried "\"C:\App Args\""? – Ken Brittain May 05 '16 at 11:25
  • @KenBrittain, Yes tried that too but no use. Once the value is passed into ITask::SetApplicationName() method it assigning without the quotes. – Davy May 05 '16 at 11:37

1 Answers1

0

Tried many different ways with ITask::SetApplicationName() method and none worked, Finally found the way to enclose the Application Path with double quotes using Task Scheduler Managed Wrapper

using (TaskService ts = new TaskService(@"\\RemoteServer"))
{
    TaskDefinition td = ts.NewTask();
    td.RegistrationInfo.Description = "Does something";

    // Create an action that will launch Notepad whenever the trigger fires
    td.Actions.Add(new ExecAction("notepad.exe", "\"c:\\Some Folder\\test.log\"", null));

    // Register the task in the root folder
    ts.RootFolder.RegisterTaskDefinition(@"Test", td);
}
Davy
  • 134
  • 5