I've searched a lot to try to resolve this issue. It seems like I'm doing the correct things (td.Principal.LogonType = TaskLogonType.Password and providing a login/password). The scheduled task is created but when I look at the scheduled task it always has the "Run only if logged in" checkbox checked. If I uncheck that box and save it, it works perfectly. So it seems like I'm close.
Here's the code:
Thanks for any help on this.
Here's the code:
Sub ScheduleWithTaskManager(Scheduleid AsInteger, OneTime AsBoolean) Dim onetimestring AsString = "0"If OneTime Then onetimestring = "1"Using ts AsNew TaskService("", "ServiceTask", "SOD", "S3rv1c3Task") ' Create a new task definition and assign propertiesDim td As TaskDefinition = ts.NewTask td.Principal.LogonType = TaskLogonType.Password td.RegistrationInfo.Description = Scheduleid & " - "& Session("ClientID") & " - "& GetName(Me.ddlPages.SelectedItem.Text) td.Settings.RunOnlyIfLoggedOn = FalseIf OneTime ThenDim tt As TimeTrigger = New TimeTrigger tt.StartBoundary = GetNextExecution(OneTime) td.Triggers.Add(tt) ElseIf ddlPeriodUnits.SelectedValue = "Day"ThenDim dt As DailyTrigger = New DailyTrigger() dt.StartBoundary = GetNextExecution() dt.DaysInterval = 1 td.Triggers.Add(dt) ElseIf ddlPeriodUnits.SelectedValue = "Week"ThenDim wt As WeeklyTrigger = New WeeklyTrigger wt.StartBoundary = GetNextExecution() wt.DaysOfWeek = GetDayoftheweek(ddlDayOf.SelectedValue) td.Triggers.Add(wt) ElseIf ddlPeriodUnits.SelectedValue = "Month"ThenDim mt As MonthlyTrigger = New MonthlyTrigger mt.StartBoundary = GetNextExecution() If ddlDayOf.SelectedValue = 0 Then mt.RunOnLastDayOfMonth = TrueElseDim dayof(1) AsInteger dayof(0) = ddlDayOf.SelectedValue mt.DaysOfMonth = dayof EndIf td.Triggers.Add(mt) EndIfTry'td.Settings.RunOnlyIfLoggedOn = FalseDim domain AsString = "portal.securityondemand.com"'Request.ServerVariables("HTTP_HOST")Dim path AsString = Server.MapPath("~/bin") Dim arguments AsString = onetimestring & " "& Scheduleid & " 40 "& domain td.Actions.Add(New ExecAction(path & "/RunReport.exe", arguments, path)) ' Register the task in the root folder ts.RootFolder.RegisterTaskDefinition(Scheduleid, td) Catch ex As Exception lbErrMsg.Text = "Problem with registering with scheduler: "& ex.Message EndTryEndUsingEndSub