peass-ng/PEASS-ng · error · ArgumentOutOfRangeException

Specified argument was out of the range of valid values. (Pa

Error message

Specified argument was out of the range of valid values. (Parameter 'createType')

What it means

TaskFolder.RegisterTaskDefinition throws ArgumentOutOfRangeException when the TaskCreation value passed as createType is not one of the creation types supported by Task Scheduler 1.0 (e.g. IgnoreRegistrationTriggers, ValidateOnly, or other unsupported flags). The library only supports a subset of TaskCreation values on the legacy v1 scheduler, and anything falling through the switch's default case is rejected with this exception naming the 'createType' parameter.

Source

Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolder.cs:572

            switch (createType)
            {
                case TaskCreation.Create:
                case TaskCreation.CreateOrUpdate:
                case TaskCreation.Disable:
                case TaskCreation.Update:
                    if (createType == TaskCreation.Disable)
                        definition.Settings.Enabled = false;
                    definition.V1Save(path);
                    break;
                case TaskCreation.DontAddPrincipalAce:
                    throw new NotV1SupportedException("Security settings are not available on Task Scheduler 1.0.");
                case TaskCreation.IgnoreRegistrationTriggers:
                    throw new NotV1SupportedException("Registration triggers are not available on Task Scheduler 1.0.");
                case TaskCreation.ValidateOnly:
                    throw new NotV1SupportedException("XML validation not available on Task Scheduler 1.0.");
                default:
                    throw new ArgumentOutOfRangeException(nameof(createType), createType, null);
            }
            return new Task(TaskService, definition.v1Task);
        }

        /// <summary>
        /// Applies access control list (ACL) entries described by a <see cref="TaskSecurity"/> object to the file described by the current <see cref="TaskFolder"/> object.
        /// </summary>
        /// <param name="taskSecurity">A <see cref="TaskSecurity"/> object that describes an access control list (ACL) entry to apply to the current folder.</param>
        public void SetAccessControl([NotNull] TaskSecurity taskSecurity) { taskSecurity.Persist(this); }

        /// <summary>
        /// Sets the security descriptor for the folder. Not available to Task Scheduler 1.0.
        /// </summary>
        /// <param name="sd">The security descriptor for the folder.</param>
        /// <param name="includeSections">Section(s) of the security descriptor to set.</param>
        [Obsolete("This method will be removed in deference to the SetAccessControl and SetSecurityDescriptorSddlForm methods.")]
        public void SetSecurityDescriptor([NotNull] GenericSecurityDescriptor sd, SecurityInfos includeSections = Task.defaultSecurityInfosSections) { SetSecurityDescriptorSddlForm(sd.GetSddlForm((AccessControlSections)includeSections)); }

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Check TaskService.HighestSupportedVersion / use a v2-compatible connection before using advanced TaskCreation values
  2. Use TaskCreation.Create or another v1-supported value when targeting Task Scheduler 1.0
  3. Catch NotV1SupportedException/ArgumentOutOfRangeException and fall back to a simplified registration path

Example fix

// before
folder.RegisterTaskDefinition(name, def, TaskCreation.ValidateOnly, null, null, TaskLogonType.InteractiveToken);
// after
if (ts.HighestSupportedVersion >= TaskSchedulerVersion.V2)
    folder.RegisterTaskDefinition(name, def, TaskCreation.ValidateOnly, null, null, TaskLogonType.InteractiveToken);
else
    folder.RegisterTaskDefinition(name, def, TaskCreation.Create, null, null, TaskLogonType.InteractiveToken);
Defensive patterns

Strategy: validation

Validate before calling

bool v1 = ts.HighestSupportedVersion < TaskSchedulerVersion.V2;
if (v1 && (createType == TaskCreation.IgnoreRegistrationTriggers || createType == TaskCreation.ValidateOnly))
    throw new NotSupportedException("TaskCreation value unsupported on Task Scheduler 1.0.");

Try / catch

try { folder.RegisterTaskDefinition(name, def, createType, userId, pwd, logonType); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "createType") { /* fall back to TaskCreation.Create */ }

Prevention

When it happens

Trigger: Calling TaskFolder.RegisterTask or RegisterTaskDefinition on a system/folder bound to Task Scheduler 1.0 (v2Folder == null) with createType set to TaskCreation.IgnoreRegistrationTriggers, TaskCreation.ValidateOnly, or any other TaskCreation value not handled by the v1 switch.

Common situations: Code written against Task Scheduler 2.0 features (XML validation, registration triggers) being run on Windows XP / Server 2003, or on a task path/folder that the library resolved to the v1 root folder; copied sample code using ValidateOnly without a v2 check.

Related errors


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