peass-ng/PEASS-ng · error · ArgumentException
Path not found
Error message
Path not found
What it means
The TaskFolderCollection indexer throws ArgumentException('Path not found') when the requested folder path cannot be resolved: the underlying GetFolder call fails on v2, and on v1 the path is not the empty/root path. The library swallows the original COM exception and rethrows this generic ArgumentException naming the 'path' parameter.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs:67
}
}
/// <summary>Gets the specified folder from the collection.</summary>
/// <param name="path">The path of the folder to be retrieved.</param>
/// <returns>A TaskFolder instance that represents the requested folder.</returns>
public TaskFolder this[[NotNull] string path]
{
get
{
try
{
if (v2FolderList != null)
return parent.GetFolder(path);
if (v1FolderList != null && v1FolderList.Length > 0 && (path == string.Empty || path == "\\"))
return v1FolderList[0];
}
catch { }
throw new ArgumentException(@"Path not found", nameof(path));
}
}
/// <summary>Adds an item to the <see cref="ICollection{T}"/>.</summary>
/// <param name="item">The object to add to the <see cref="ICollection{T}"/>.</param>
/// <exception cref="System.NotImplementedException">
/// This action is technically unfeasible due to limitations of the underlying library. Use the <see
/// cref="TaskFolder.CreateFolder(string, string, bool)"/> instead.
/// </exception>
public void Add([NotNull] TaskFolder item) => throw new NotImplementedException();
/// <summary>Removes all items from the <see cref="ICollection{T}"/>.</summary>
public void Clear()
{
if (v2FolderList != null)
{
for (var i = v2FolderList.Count; i > 0; i--)
parent.DeleteFolder(v2FolderList[i].Name, false);View on GitHub (pinned to 53fb989abc)
Solutions
- Verify the folder path exists before lookup (catch this ArgumentException)
- Use the leading '\' and exact casing in the path
- Iterate SubFolders to check available names instead of guessing paths
Example fix
// before
var folder = ts.GetFolder("\\MyApp\Tasks");
// after
TaskFolder folder = null;
try { folder = ts.GetFolder("\\MyApp\Tasks"); }
catch (ArgumentException) { folder = ts.RootFolder.CreateFolder("\\MyApp\Tasks"); } Defensive patterns
Strategy: try-catch
Validate before calling
static bool FolderExists(TaskService ts, string path) {
if (string.IsNullOrEmpty(path) || path == "\\") return true;
try { ts.GetFolder(path); return true; } catch (ArgumentException) { return false; }
} Try / catch
try { folder = ts.GetFolder(path); }
catch (ArgumentException ex) when (ex.Message.Contains("Path not found")) { folder = ts.RootFolder; } Prevention
- Always prefix folder paths with '\'
- Enumerate RootFolder/SubFolders to discover valid paths instead of guessing
- Cache resolved TaskFolder references instead of repeated lookups
When it happens
Trigger: Accessing TaskService.GetFolder(path) / folder.SubFolders[path] with a path that does not exist, is misspelled, or uses the wrong separator (must start with '\'), on a folder whose subfolder lookup fails.
Common situations: Enumerating tasks when an expected folder was deleted or renamed; assuming '\Microsoft\Windows\...' paths exist on down-level systems; passing a folder name without the leading backslash.
Related errors
- Exception of type 'System.ArgumentException' was thrown.
- Resources.Cannot_Create_Directory
- Network path is not allowed for directory junction: [{0}]
- The system cannot find the path specified: [path]
- Invalid Subpath
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/4bfb1a081cbfe9ce.
Report an issue: GitHub.