{"record":{"id":"7ad54baa98fd2997","repo":"peass-ng/PEASS-ng","slug":"a-task-must-be-registered-with-at-least-one-action","errorCode":null,"errorMessage":"A task must be registered with at least one action and no more than 32 actions.","messagePattern":"A task must be registered with at least one action and no more than 32 actions\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolder.cs","lineNumber":484,"sourceCode":"        /// \n        /// // Create an action that will launch Notepad whenever the trigger fires\n        /// td.Actions.Add(\"notepad.exe\", \"c:\\\\test.log\");\n        /// \n        /// // Register the task in the root folder of the local machine using the current user and the S4U logon type\n        /// TaskService.Instance.RootFolder.RegisterTaskDefinition(\"Test\", td);\n        /// ]]></code>\n        /// <para>This example registers that same task using the SYSTEM account.</para>\n        /// <code lang=\"cs\"><![CDATA[\n        /// TaskService.Instance.RootFolder.RegisterTaskDefinition(\"TaskName\", taskDefinition, TaskCreation.CreateOrUpdate, \"SYSTEM\", null, TaskLogonType.ServiceAccount);\n        /// ]]></code>\n        /// <para>This example registers that same task using a specific username and password along with a security definition.</para>\n        /// <code lang=\"cs\"><![CDATA[\n        /// TaskService.Instance.RootFolder.RegisterTaskDefinition(\"TaskName\", taskDefinition, TaskCreation.CreateOrUpdate, \"userDomain\\\\userName\", \"userPassword\", TaskLogonType.Password, @\"O:BAG:DUD:(A;ID;0x1f019f;;;BA)(A;ID;0x1f019f;;;SY)(A;ID;FA;;;BA)(A;;FR;;;BU)\");\n        /// ]]></code></example>\n        public Task RegisterTaskDefinition([NotNull] string path, [NotNull] TaskDefinition definition, TaskCreation createType, string userId, string password = null, TaskLogonType logonType = TaskLogonType.S4U, string sddl = null)\n        {\n            if (definition.Actions.Count < 1 || definition.Actions.Count > 32)\n                throw new ArgumentOutOfRangeException(nameof(definition.Actions), @\"A task must be registered with at least one action and no more than 32 actions.\");\n\n            userId ??= definition.Principal.Account;\n            if (userId == string.Empty) userId = null;\n            User user = new User(userId);\n            if (v2Folder != null)\n            {\n                definition.Actions.ConvertUnsupportedActions();\n                if (logonType == TaskLogonType.ServiceAccount)\n                {\n                    if (string.IsNullOrEmpty(userId) || !user.IsServiceAccount)\n                        throw new ArgumentException(@\"A valid system account name must be supplied for TaskLogonType.ServiceAccount. Valid entries are \"\"NT AUTHORITY\\SYSTEM\"\", \"\"SYSTEM\"\", \"\"NT AUTHORITY\\LOCALSERVICE\"\", or \"\"NT AUTHORITY\\NETWORKSERVICE\"\".\", nameof(userId));\n                    if (password != null)\n                        throw new ArgumentException(@\"A password cannot be supplied when specifying TaskLogonType.ServiceAccount.\", nameof(password));\n                }\n                /*else if ((LogonType == TaskLogonType.Password || LogonType == TaskLogonType.InteractiveTokenOrPassword ||\n\t\t\t\t\t(LogonType == TaskLogonType.S4U && UserId != null && !user.IsCurrent)) && password == null)\n\t\t\t\t{\n\t\t\t\t\tthrow new ArgumentException(\"A password must be supplied when specifying TaskLogonType.Password or TaskLogonType.InteractiveTokenOrPassword or TaskLogonType.S4U from another account.\", nameof(password));","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolder.cs#L466-L502","documentation":"RegisterTaskDefinition validates that the task definition has between 1 and 32 actions and throws ArgumentOutOfRangeException otherwise. The Windows Task Scheduler requires at least one action per registered task and caps actions at 32.","triggerScenarios":"Calling RegisterTaskDefinition (directly or via RegisterTask) with a TaskDefinition whose Actions collection is empty, or programmatically appending more than 32 actions.","commonSituations":"Building a TaskDefinition without calling Actions.Add (forgot to add an ExecAction); loops that batch-generate tasks and exceed the 32-action cap; merging action lists from configuration without bounding them.","solutions":["Add at least one action, e.g. definition.Actions.Add(new ExecAction(\"cmd.exe\", \"/c script\")), before registering","Split tasks exceeding 32 actions into multiple registered tasks or chained tasks","Validate definition.Actions.Count in [1,32] before calling RegisterTaskDefinition"],"exampleFix":"// before\nvar td = ts.NewTask();\n// forgot to add an action\nrootFolder.RegisterTaskDefinition(\"MyTask\", td);\n// after\nvar td = ts.NewTask();\ntd.Actions.Add(new ExecAction(\"notepad.exe\"));\nrootFolder.RegisterTaskDefinition(\"MyTask\", td);","handlingStrategy":"validation","validationCode":"if (definition.Actions.Count < 1 || definition.Actions.Count > 32) throw new InvalidOperationException(\"Task must have 1-32 actions\");","typeGuard":null,"tryCatchPattern":"try { root.RegisterTaskDefinition(name, td); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"definition.Actions\") { /* add/split actions */ }","preventionTips":["Always add at least one action to a new TaskDefinition","Cap generated action lists at 32; split into multiple tasks beyond that","Assert action count in unit tests for task-creation helpers"],"tags":["argumentoutofrange","taskscheduler","validation","actions"],"backgroundTag":"task-action-count-violation","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}