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 );