Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

Commented Unassigned: Error using RegisterTaskDefinition on Window10 Professional [12169]

$
0
0
______Error using RegisterTaskDefinition on Window10 Proffessional______

When calling "RegisterTaskDefinition", the error I am getting is:

the task xml contains a value which is incorrectly formatted or out of range
Exception from HResult:0x80041318

Any help is appreciated.
Comments: ** Comment from web user: shilpa0812 **

Thanks for looking into the issue. I am getting the error while running the code on Windows 10 professional only. On other windows versions it is working correctly. The code is as following:

public void CreateSchedulerTask()
{
try
{
using (TaskService taskService = new TaskService())
{

bool IsNewer = taskService.HighestSupportedVersion > new Version(1, 2);
//Retrieve Assembly Path
string pathForExe = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Program.exe");

//Delete taks if exists
taskService.RootFolder.DeleteTask("SomeTask", false);

// Create a new task definition and assign properties
TaskDefinition taskDefinition = taskService.NewTask();

//Security
taskDefinition.Principal.LogonType = TaskLogonType.InteractiveToken;
taskDefinition.Principal.UserId = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

//This property not supported in XP
if (IsNewer)
{
taskDefinition.Principal.RunLevel = TaskRunLevel.Highest;
}

taskDefinition.RegistrationInfo.Description = "Keeps your software up to date. If this task is disabled or stopped, your software will not be kept up to date, meaning security vulnerabilities that may arise cannot be fixed and features may not work. This task uninstalls itself when there is no software using it.";

// Add a trigger that, starting every month
// and Saturday and repeat every 10 minutes for the following 11 hours
MonthlyTrigger monthlyTrigger = new MonthlyTrigger();
monthlyTrigger.EndBoundary = DateTime.Now.AddYears(10);
taskDefinition.Triggers.Add(monthlyTrigger);

// Create an action that will launch Notepad whenever the trigger fires
taskDefinition.Actions.Add(new ExecAction(pathForExe));

// Register the task in the root folder
taskService.RootFolder.RegisterTaskDefinition("SomeTask", taskDefinition);
}
}
catch (Exception ex)
{
logger.Error(ex);
ServiceHelper.LogError(ex);
}
}


Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>