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

New Post: Unauthorized Exception when creating/deleting tasks

$
0
0

This is the latest code I tried. I'm pretty sure I'm just missing something small. Your help is greatly appreciated:


var taskDef = ts.NewTask();

if (ts.HighestSupportedVersion >= new Version(1, 2))
{
	taskDef.Principal.RunLevel = TaskRunLevel.LUA;
}
else
{
	taskDef.Settings.RunOnlyIfLoggedOn = true;
}

string userId = string.Concat(Environment.UserDomainName, "\\", Environment.UserName);

taskDef.Principal.LogonType = TaskLogonType.S4U;
taskDef.Principal.UserId = userId;

taskDef.RegistrationInfo.Description = string.Format(
							Resources.Scheduled_Task_Desc_Format,
							this.TargetEntity.FriendlyName
						);
taskDef.Triggers.Add(GetTrigger(_syncSettingsViewModel.Interval));
taskDef.Actions.Add(
				new ExecAction(
					Assembly.GetEntryAssembly().Location,
					"-s " + GetSyncFlowName(this.TargetEntity)
				)
			);


ts.RootFolder.RegisterTaskDefinition(
				taskName, 
				taskDef,
				TaskCreation.CreateOrUpdate,
				userId,
				LogonType: TaskLogonType.S4U
			);

Viewing all articles
Browse latest Browse all 2206

Trending Articles



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