peass-ng/PEASS-ng · error · ArgumentNullException

Value cannot be null. (Parameter 'folderSecurity')

Error message

Value cannot be null. (Parameter 'folderSecurity')

What it means

TaskFolder.CreateFolder(string, TaskSecurity) is annotated [NotNull] for folderSecurity and explicitly throws ArgumentNullException when it is null. The security descriptor is required to derive the SDDL string passed to the underlying COM CreateFolder call.

Source

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

        /// <summary>
        /// Creates a folder for related tasks. Not available to Task Scheduler 1.0.
        /// </summary>
        /// <param name="subFolderName">The name used to identify the folder. If "FolderName\SubFolder1\SubFolder2" is specified, the entire folder tree will be created if the folders do not exist. This parameter can be a relative path to the current <see cref="TaskFolder"/> instance. The root task folder is specified with a backslash (\). An example of a task folder path, under the root task folder, is \MyTaskFolder. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be used to specify the parent task folder in the path.</param>
        /// <param name="sd">The security descriptor associated with the folder.</param>
        /// <returns>A <see cref="TaskFolder"/> instance that represents the new subfolder.</returns>
        [Obsolete("This method will be removed in deference to the CreateFolder(string, TaskSecurity) method.")]
        public TaskFolder CreateFolder([NotNull] string subFolderName, GenericSecurityDescriptor sd) => CreateFolder(subFolderName, sd == null ? null : sd.GetSddlForm(Task.defaultAccessControlSections));

        /// <summary>
        /// Creates a folder for related tasks. Not available to Task Scheduler 1.0.
        /// </summary>
        /// <param name="subFolderName">The name used to identify the folder. If "FolderName\SubFolder1\SubFolder2" is specified, the entire folder tree will be created if the folders do not exist. This parameter can be a relative path to the current <see cref="TaskFolder"/> instance. The root task folder is specified with a backslash (\). An example of a task folder path, under the root task folder, is \MyTaskFolder. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be used to specify the parent task folder in the path.</param>
        /// <param name="folderSecurity">The task security associated with the folder.</param>
        /// <returns>A <see cref="TaskFolder"/> instance that represents the new subfolder.</returns>
        public TaskFolder CreateFolder([NotNull] string subFolderName, [NotNull] TaskSecurity folderSecurity)
        {
            if (folderSecurity == null)
                throw new ArgumentNullException(nameof(folderSecurity));
            return CreateFolder(subFolderName, folderSecurity.GetSecurityDescriptorSddlForm(Task.defaultAccessControlSections));
        }

        /// <summary>
        /// Creates a folder for related tasks. Not available to Task Scheduler 1.0.
        /// </summary>
        /// <param name="subFolderName">The name used to identify the folder. If "FolderName\SubFolder1\SubFolder2" is specified, the entire folder tree will be created if the folders do not exist. This parameter can be a relative path to the current <see cref="TaskFolder" /> instance. The root task folder is specified with a backslash (\). An example of a task folder path, under the root task folder, is \MyTaskFolder. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be used to specify the parent task folder in the path.</param>
        /// <param name="sddlForm">The security descriptor associated with the folder.</param>
        /// <param name="exceptionOnExists">Set this value to false to avoid having an exception called if the folder already exists.</param>
        /// <returns>A <see cref="TaskFolder" /> instance that represents the new subfolder.</returns>
        /// <exception cref="System.Security.SecurityException">Security descriptor mismatch between specified credentials and credentials on existing folder by same name.</exception>
        /// <exception cref="System.ArgumentException">Invalid SDDL form.</exception>
        /// <exception cref="Microsoft.Win32.TaskScheduler.NotV1SupportedException">Not supported under Task Scheduler 1.0.</exception>
        public TaskFolder CreateFolder([NotNull] string subFolderName, string sddlForm = null, bool exceptionOnExists = true)
        {
            if (v2Folder == null) throw new NotV1SupportedException();
            ITaskFolder ifld = null;
            try { ifld = v2Folder.CreateFolder(subFolderName, sddlForm); }

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Pass a valid TaskSecurity instance, e.g. new TaskSecurity(), or default folder security
  2. Use the overload CreateFolder(string, string sddlForm, bool) if default security is desired
  3. Add a null check on the TaskSecurity argument at the call site

Example fix

// before
rootFolder.CreateFolder("MyFolder", null);
// after
var security = new TaskSecurity();
rootFolder.CreateFolder("MyFolder", security);
Defensive patterns

Strategy: validation

Validate before calling

if (folderSecurity == null) folderSecurity = new TaskSecurity();

Try / catch

try { folder.CreateFolder(name, sec); }
catch (ArgumentNullException) { /* supply a TaskSecurity */ }

Prevention

When it happens

Trigger: Calling CreateFolder("name", null) with the TaskSecurity overload — the null check runs before GetSecurityDescriptorSddlForm is invoked.

Common situations: Developer omits the security parameter thinking it's optional; refactoring code that previously used the string-sddl overload; passing a variable that failed to initialize.

Related errors


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