peass-ng/PEASS-ng · error · NotV2SupportedException

Task Scheduler 2.0 (1.2) does not support setting this prope

Error message

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.

What it means

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.

Source

Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs:3412

                    v1Task.SetFlags(TaskFlags.StartOnlyIfIdle, value);
                OnNotifyPropertyChanged();
            }
        }

        /// <summary>
        /// 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)
        /// </summary>
        /// <exception cref="NotV2SupportedException">Property set for a task on a Task Scheduler version other than 1.0.</exception>
        [XmlIgnore]
        public bool RunOnlyIfLoggedOn
        {
            get => v2Settings != null || v1Task.HasFlags(TaskFlags.RunOnlyIfLoggedOn);
            set
            {
                if (v1Task != null)
                    v1Task.SetFlags(TaskFlags.RunOnlyIfLoggedOn, value);
                else if (v2Settings != null)
                    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.");
                OnNotifyPropertyChanged();
            }
        }

        /// <summary>Gets or sets a Boolean value that indicates that the Task Scheduler will run the task only when a network is available.</summary>
        [DefaultValue(false)]
        public bool RunOnlyIfNetworkAvailable
        {
            get => v2Settings?.RunOnlyIfNetworkAvailable ?? v1Task.HasFlags(TaskFlags.RunIfConnectedToInternet);
            set
            {
                if (v2Settings != null)
                    v2Settings.RunOnlyIfNetworkAvailable = value;
                else
                    v1Task.SetFlags(TaskFlags.RunIfConnectedToInternet, value);
                OnNotifyPropertyChanged();
            }
        }

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Use TaskLogonType.InteractiveToken instead: principal.LogonType = TaskLogonType.InteractiveToken
  2. Remove the RunOnlyIfLoggedOn assignment for v2 definitions
  3. Set it only when v1Task != null (legacy path)
  4. Guard the setter in try-catch for NotV2SupportedException when supporting both v1 and v2

Example fix

// before
principal.RunOnlyIfLoggedOn = true;
// after
if (svc.HighestSupportedVersion < TaskServiceVersion.V2)
    principal.RunOnlyIfLoggedOn = true;
else
    principal.LogonType = TaskLogonType.InteractiveToken;
Defensive patterns

Strategy: validation

Validate before calling

if (svc.HighestSupportedVersion >= TaskServiceVersion.V2)
    principal.LogonType = TaskLogonType.InteractiveToken; // don't set RunOnlyIfLoggedOn
else
    principal.RunOnlyIfLoggedOn = true;

Try / catch

try { principal.RunOnlyIfLoggedOn = true; }
catch (NotV2SupportedException) { principal.LogonType = TaskLogonType.InteractiveToken; }

Prevention

When it happens

Trigger: Setting taskDefinition.Principal.RunOnlyIfLoggedOn = true/false on a v2 task definition (v2Settings != null, v1Task == null), i.e. any modern Windows task.

Common situations: 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+.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/cf2697eea22f0864. Report an issue: GitHub.