{"record":{"id":"df6d5da725dc1f40","repo":"peass-ng/PEASS-ng","slug":"error-file-read-only-df6d5d","errorCode":"ERROR_FILE_READ_ONLY","errorMessage":"({6000}) The file is read-only: [{pathLp}]","messagePattern":"\\((.+?)\\) The file is read-only: \\[(.+?)\\]","errorType":"exception","errorClass":"FileReadOnlyException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File Core Methods/File.DeleteFileCore.cs","lineNumber":127,"sourceCode":"\n                  // MSDN: .NET 3.5+: UnauthorizedAccessException: Path is a directory.\n                  if (IsDirectory(attributes))\n                     throw new UnauthorizedAccessException(string.Format(CultureInfo.InvariantCulture, \"({0}) {1}\", lastError.ToString(CultureInfo.InvariantCulture), string.Format(CultureInfo.InvariantCulture, Resources.Target_File_Is_A_Directory, pathLp)));\n\n\n                  if (IsReadOnlyOrHidden(attributes))\n                  {\n                     if (ignoreReadOnly)\n                     {\n                        // Reset attributes to Normal.\n                        SetAttributesCore(transaction, false, pathLp, FileAttributes.Normal, PathFormat.LongFullPath);\n\n                        goto startDeleteFile;\n                     }\n\n\n                     // MSDN: .NET 3.5+: UnauthorizedAccessException: Path specified a read-only file.\n                     throw new FileReadOnlyException(pathLp);\n                  }\n\n                  \n                  // MSDN: .NET 3.5+: UnauthorizedAccessException: The caller does not have the required permission.\n                  if (attributes == 0)\n                     NativeError.ThrowException(lastError, pathLp);\n\n                  break;\n            }\n\n            // MSDN: .NET 3.5+: IOException:\n            // The specified file is in use.\n            // There is an open handle on the file, and the operating system is Windows XP or earlier.\n\n            NativeError.ThrowException(lastError, IsDirectory(attributes), pathLp);\n         }\n      }\n   }","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File Core Methods/File.DeleteFileCore.cs#L109-L145","documentation":"DeleteFileCore throws FileReadOnlyException (derived to include Win32 error 6000, ERROR_FILE_READ_ONLY) when the target file has the ReadOnly/hidden attribute and ignoreReadOnly was not set. Windows refuses to delete read-only files, so AlphaFS surfaces a specific typed exception instead of a generic UnauthorizedAccessException.","triggerScenarios":"File.Delete or File.DeleteTransacted on a file with FileAttributes.ReadOnly while passing ignoreReadOnly=false (the default).","commonSituations":"Deleting files copied from CD/DVD or version-control working copies that are marked read-only; temp files created read-only by another tool; cleanup scripts failing on locked read-only artifacts.","solutions":["Call File.Delete(path, true) / pass ignoreReadOnly:true to clear the read-only attribute first","Clear the attribute manually before delete: File.SetAttributes(path, attrs & ~FileAttributes.ReadOnly)","Catch FileReadOnlyException and handle the file separately"],"exampleFix":"// before\nFile.Delete(path); // throws on read-only file\n// after\nvar attrs = File.GetAttributes(path);\nif ((attrs & FileAttributes.ReadOnly) != 0)\n    File.SetAttributes(path, attrs & ~FileAttributes.ReadOnly);\nFile.Delete(path);","handlingStrategy":"validation","validationCode":"var attrs = File.GetAttributes(path);\nif ((attrs & FileAttributes.ReadOnly) != 0) File.SetAttributes(path, attrs & ~FileAttributes.ReadOnly);","typeGuard":"bool IsReadOnlyFile(string p) => File.GetAttributes(p).HasFlag(FileAttributes.ReadOnly);","tryCatchPattern":"try { File.Delete(path); }\ncatch (FileReadOnlyException) { var a = File.GetAttributes(path); File.SetAttributes(path, a & ~FileAttributes.ReadOnly); File.Delete(path); }","preventionTips":["Clear read-only attributes before delete operations in cleanup code","Decide a policy for read-only files (force-delete vs skip) and centralize it","Be aware files from optical media and VCS checkouts are often read-only"],"tags":["read-only","file-attributes","io","delete"],"backgroundTag":"file-is-read-only","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}