{"record":{"id":"0c4b9f15a80a6445","repo":"peass-ng/PEASS-ng","slug":"error-file-read-only-0c4b9f","errorCode":"ERROR_FILE_READ_ONLY","errorMessage":"({6000}) The file is read-only: [{path}]","messagePattern":"\\((.+?)\\) The file is read-only: \\[(.+?)\\]","errorType":"exception","errorClass":"DirectoryReadOnlyException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File Core Methods/File.EncryptDecryptFileCore.cs","lineNumber":108,"sourceCode":"\n\n         if (!success)\n         {\n            switch ((uint) lastError)\n            {\n               case Win32Errors.ERROR_ACCESS_DENIED:\n\n                  if (!string.Equals(\"NTFS\", new DriveInfo(path).DriveFormat, StringComparison.OrdinalIgnoreCase))\n\n                     throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, \"The drive does not support NTFS encryption: [{0}]\", Path.GetPathRoot(path, false)));\n\n                  break;\n\n\n               case Win32Errors.ERROR_FILE_READ_ONLY:\n\n                  if (isFolder)\n                     throw new DirectoryReadOnlyException(path);\n\n                  else\n                     throw new FileReadOnlyException(path);\n\n\n               default:\n                  NativeError.ThrowException(lastError, isFolder, path);\n                  break;\n            }\n         }\n      }\n   }\n}\n","sourceCodeStart":90,"sourceCodeEnd":122,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File Core Methods/File.EncryptDecryptFileCore.cs#L90-L122","documentation":"EncryptDecryptFileCore handles Win32 ERROR_FILE_READ_ONLY (6000) by throwing DirectoryReadOnlyException when the target is a folder, otherwise FileReadOnlyException — surfaced as 'The file is read-only: [path]'. EFS cannot encrypt/decrypt read-only items, so AlphaFS reports the specific attribute problem. The message text is the path template; the bracketed index tag (75 vs 76) marks the same throw for the file branch.","triggerScenarios":"Calling File.Encrypt or File.Decrypt on a file whose attributes include ReadOnly; the native call fails with ERROR_FILE_READ_ONLY and isFolder==false.","commonSituations":"Files copied from read-only media (CD/DVD); files checked out read-only from source control; folders inheriting read-only attributes; automation runs under an account that cannot modify attributes.","solutions":["Clear the read-only attribute before calling Encrypt/Decrypt: File.SetAttributes(path, attrs & ~FileAttributes.ReadOnly)","Check the attributes before the call and skip or unblock read-only items","Catch FileReadOnlyException and report/handle the specific path"],"exampleFix":"// before\nFile.Encrypt(path); // fails if read-only\n// after\nvar attrs = File.GetAttributes(path);\nif ((attrs & FileAttributes.ReadOnly) != 0)\n    File.SetAttributes(path, attrs & ~FileAttributes.ReadOnly);\nFile.Encrypt(path);","handlingStrategy":"validation","validationCode":"var attrs = File.GetAttributes(path);\nif ((attrs & FileAttributes.ReadOnly) != 0) File.SetAttributes(path, attrs & ~FileAttributes.ReadOnly);","typeGuard":"bool IsReadOnlyEntry(string p) => File.GetAttributes(p).HasFlag(FileAttributes.ReadOnly);","tryCatchPattern":"try { File.Encrypt(path); }\ncatch (FileReadOnlyException) { var a = File.GetAttributes(path); File.SetAttributes(path, a & ~FileAttributes.ReadOnly); File.Encrypt(path); }","preventionTips":["Normalize file attributes before encrypt/decrypt batches","Skip or unblock read-only files in batch EFS operations","Log which paths were read-only so operators can review"],"tags":["read-only","file-attributes","encryption","efs"],"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"}