{"record":{"id":"281eddb9d556597e","repo":"peass-ng/PEASS-ng","slug":"error-file-read-only-281edd","errorCode":"ERROR_FILE_READ_ONLY","errorMessage":"({6000}) The file is read-only: [{destinationPathLp}]","messagePattern":"\\((.+?)\\) The file is read-only: \\[(.+?)\\]","errorType":"exception","errorClass":"FileReadOnlyException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File CopyMove/File.RestartMoveOrThrowException.cs","lineNumber":158,"sourceCode":"                  if (isMove && IsReadOnlyOrHidden(attrs.dwFileAttributes))\n                  {\n                     if (HasReplaceExisting(cma.MoveOptions))\n                     {\n                        // Reset attributes to Normal.\n                        SetAttributesCore(cma.Transaction, isFolder, destinationPathLp, FileAttributes.Normal, PathFormat.LongFullPath);\n\n\n                        restart = true;\n                        break;\n                     }\n\n\n                     // MSDN: .NET 3.5+: UnauthorizedAccessException: destinationPath is read-only.\n                     // MSDN: Win32 CopyFileXxx: This function fails with ERROR_ACCESS_DENIED if the destination file already exists\n                     // and has the FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_READONLY attribute set.\n\n                     if (!retry)\n                        throw new FileReadOnlyException(destinationPathLp);\n                  }\n               }\n\n\n               // MSDN: .NET 3.5+: An I/O error has occurred. \n               // File.Copy(): IOException: destinationPath exists and overwrite is false.\n               // File.Move(): The destination file already exists or sourcePath was not found.\n\n               if (!retry)\n                  NativeError.ThrowException(lastError, isFolder, fileNameLp);\n\n               break;\n         }\n\n\n         return restart;\n      }\n   }","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File CopyMove/File.RestartMoveOrThrowException.cs#L140-L176","documentation":"During a move/copy AlphaFS hit the Win32 error ERROR_FILE_READ_ONLY (6000-mapped here): the destination file exists with the FILE_ATTRIBUTE_READONLY attribute. Mirroring MSDN behavior for .NET CopyFile, FileReadOnlyException (subclass of UnauthorizedAccessException) is thrown for the restart/move path unless a retry is in progress.","triggerScenarios":"File.Move/File.CopyMove where the destination file already exists and has the read-only attribute set; Windows refuses to overwrite a read-only destination (Win32 CopyFileXxx also fails with ERROR_ACCESS_DENIED for hidden/read-only destinations).","commonSituations":"Overwriting files checked out of source control as read-only; copying over files from read-only media or templates; re-running a deployment that previously produced a write-protected output file.","solutions":["Clear the read-only attribute on the destination before the operation: File.SetAttributes(dst, File.GetAttributes(dst) & ~FileAttributes.ReadOnly).","Delete the existing read-only destination file first, then perform the move/copy.","Check File.Exists(dst) and its attributes beforehand and skip or archive the existing file instead of overwriting."],"exampleFix":"// before\nFile.Move(src, dst, MoveOptions.Overwrite); // FileReadOnlyException if dst is read-only\n// after\nif (File.Exists(dst))\n    File.SetAttributes(dst, File.GetAttributes(dst) & ~FileAttributes.ReadOnly);\nFile.Move(src, dst, MoveOptions.Overwrite);","handlingStrategy":"validation","validationCode":"static void ClearReadOnly(string destinationPath)\n{\n    if (File.Exists(destinationPath))\n    {\n        var attrs = File.GetAttributes(destinationPath);\n        if ((attrs & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)\n            File.SetAttributes(destinationPath, attrs & ~FileAttributes.ReadOnly);\n    }\n}\n// call ClearReadOnly(dst) before File.Move/CopyMove with overwrite","typeGuard":"static bool IsDestinationReadOnly(string dst) =>\n    File.Exists(dst) && File.GetAttributes(dst).HasFlag(FileAttributes.ReadOnly);","tryCatchPattern":"try { File.Move(src, dst, MoveOptions.Overwrite); }\ncatch (UnauthorizedAccessException)\n{\n    var attrs = File.GetAttributes(dst);\n    File.SetAttributes(dst, attrs & ~FileAttributes.ReadOnly);\n    File.Move(src, dst, MoveOptions.Overwrite);\n}","preventionTips":["Check and clear FileAttributes.ReadOnly on existing destinations before overwrite operations","Treat outputs from source control or read-only media as potentially read-only","Consider deleting the destination instead of overwriting it","Log attribute changes so silent un-protecting is visible"],"tags":["filesystem","read-only","unauthorizedaccessexception"],"backgroundTag":"destination-file-read-only","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}