{"record":{"id":"cf2697eea22f0864","repo":"peass-ng/PEASS-ng","slug":"task-scheduler-2-0-1-2-does-not-support-setting","errorCode":null,"errorMessage":"Task Scheduler 2.0 (1.2) does not support setting this property. You must use an InteractiveToken in order to have the task run in the current user session.","messagePattern":"Task Scheduler 2\\.0 \\(1\\.2\\) does not support setting this property\\. You must use an InteractiveToken in order to have the task run in the current user session\\.","errorType":"exception","errorClass":"NotV2SupportedException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs","lineNumber":3412,"sourceCode":"                    v1Task.SetFlags(TaskFlags.StartOnlyIfIdle, value);\n                OnNotifyPropertyChanged();\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets a Boolean value that indicates that the Task Scheduler will run the task only if the user is logged on (v1.0 only)\n        /// </summary>\n        /// <exception cref=\"NotV2SupportedException\">Property set for a task on a Task Scheduler version other than 1.0.</exception>\n        [XmlIgnore]\n        public bool RunOnlyIfLoggedOn\n        {\n            get => v2Settings != null || v1Task.HasFlags(TaskFlags.RunOnlyIfLoggedOn);\n            set\n            {\n                if (v1Task != null)\n                    v1Task.SetFlags(TaskFlags.RunOnlyIfLoggedOn, value);\n                else if (v2Settings != null)\n                    throw new NotV2SupportedException(\"Task Scheduler 2.0 (1.2) does not support setting this property. You must use an InteractiveToken in order to have the task run in the current user session.\");\n                OnNotifyPropertyChanged();\n            }\n        }\n\n        /// <summary>Gets or sets a Boolean value that indicates that the Task Scheduler will run the task only when a network is available.</summary>\n        [DefaultValue(false)]\n        public bool RunOnlyIfNetworkAvailable\n        {\n            get => v2Settings?.RunOnlyIfNetworkAvailable ?? v1Task.HasFlags(TaskFlags.RunIfConnectedToInternet);\n            set\n            {\n                if (v2Settings != null)\n                    v2Settings.RunOnlyIfNetworkAvailable = value;\n                else\n                    v1Task.SetFlags(TaskFlags.RunIfConnectedToInternet, value);\n                OnNotifyPropertyChanged();\n            }\n        }","sourceCodeStart":3394,"sourceCodeEnd":3430,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs#L3394-L3430","documentation":"The RunOnlyIfLoggedOn property is a Task Scheduler 1.0-only concept. On Task Scheduler 2.0 (v2Settings), it cannot be set — the equivalent behavior is achieved by using logon type InteractiveToken — so the setter throws NotV2SupportedException.","triggerScenarios":"Setting taskDefinition.Principal.RunOnlyIfLoggedOn = true/false on a v2 task definition (v2Settings != null, v1Task == null), i.e. any modern Windows task.","commonSituations":"Porting XP-era task scripts to modern Windows; code paths setting this property unconditionally; attempting to force the task into the current user's session on Vista+.","solutions":["Use TaskLogonType.InteractiveToken instead: principal.LogonType = TaskLogonType.InteractiveToken","Remove the RunOnlyIfLoggedOn assignment for v2 definitions","Set it only when v1Task != null (legacy path)","Guard the setter in try-catch for NotV2SupportedException when supporting both v1 and v2"],"exampleFix":"// before\nprincipal.RunOnlyIfLoggedOn = true;\n// after\nif (svc.HighestSupportedVersion < TaskServiceVersion.V2)\n    principal.RunOnlyIfLoggedOn = true;\nelse\n    principal.LogonType = TaskLogonType.InteractiveToken;","handlingStrategy":"validation","validationCode":"if (svc.HighestSupportedVersion >= TaskServiceVersion.V2)\n    principal.LogonType = TaskLogonType.InteractiveToken; // don't set RunOnlyIfLoggedOn\nelse\n    principal.RunOnlyIfLoggedOn = true;","typeGuard":null,"tryCatchPattern":"try { principal.RunOnlyIfLoggedOn = true; }\ncatch (NotV2SupportedException) { principal.LogonType = TaskLogonType.InteractiveToken; }","preventionTips":["Use LogonType.InteractiveToken on v2+ instead of RunOnlyIfLoggedOn","Branch on Task Scheduler version when supporting both XP and modern Windows"],"tags":["taskscheduler","notv2supported","logon-type","interop"],"backgroundTag":"unsupported-platform-feature","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}