The exception has apperad on RegisterTaskDefinition method in version 2.5.0 (in 2.4.2 all was oK):
_"The name provided is not a properly formed account name"_
```C#
private const string taskName = "MyCustomsPrintingServiceStarter";
public void Run(string installDir)
{
using (var taskService = new TaskService())
{
var task = taskService.FindTask(taskName);
if (task == null)
{
string pathToApplicationExeFile = GetPathToApplicationExeFile(installDir);
var definition = taskService.NewTask();
definition.Principal.RunLevel = TaskRunLevel.Highest;
definition.Triggers.AddNew(TaskTriggerType.Logon);
definition.Actions.Add(new ExecAction(pathToApplicationExeFile, workingDirectory: Path.GetDirectoryName(pathToApplicationExeFile)));
definition.Settings.DisallowStartIfOnBatteries = false;
definition.Settings.StopIfGoingOnBatteries = false;
definition.Settings.ExecutionTimeLimit = TimeSpan.Zero;
task = taskService.RootFolder.RegisterTaskDefinition(
taskName, definition, TaskCreation.Create, "Everyone", LogonType: TaskLogonType.Group);
}
task.Run();
}
}
```
_"The name provided is not a properly formed account name"_
```C#
private const string taskName = "MyCustomsPrintingServiceStarter";
public void Run(string installDir)
{
using (var taskService = new TaskService())
{
var task = taskService.FindTask(taskName);
if (task == null)
{
string pathToApplicationExeFile = GetPathToApplicationExeFile(installDir);
var definition = taskService.NewTask();
definition.Principal.RunLevel = TaskRunLevel.Highest;
definition.Triggers.AddNew(TaskTriggerType.Logon);
definition.Actions.Add(new ExecAction(pathToApplicationExeFile, workingDirectory: Path.GetDirectoryName(pathToApplicationExeFile)));
definition.Settings.DisallowStartIfOnBatteries = false;
definition.Settings.StopIfGoingOnBatteries = false;
definition.Settings.ExecutionTimeLimit = TimeSpan.Zero;
task = taskService.RootFolder.RegisterTaskDefinition(
taskName, definition, TaskCreation.Create, "Everyone", LogonType: TaskLogonType.Group);
}
task.Run();
}
}
```