{"record":{"id":"f5276e9c11ebf770","repo":"peass-ng/PEASS-ng","slug":"error-not-ready","errorCode":"ERROR_NOT_READY","errorMessage":"({21}) The device is not ready: [{drive}]","messagePattern":"\\((.+?)\\) The device is not ready: \\[(.+?)\\]","errorType":"exception","errorClass":"DeviceNotReadyException","httpStatus":null,"severity":"warning","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory.ExistsDrive.cs","lineNumber":76,"sourceCode":"\n\n      /// <summary>[AlphaFS] Checks if specified <paramref name=\"path\"/> is a local- or network drive.</summary>\n      /// <returns><c>true</c> if the drive exists, <c>false</c> otherwise.</returns>\n      internal static bool ExistsDriveOrFolderOrFile(KernelTransaction transaction, string path, bool isFolder, int lastError, bool throwIfDriveNotExists, bool throwIfFolderOrFileNotExists)\n      {\n         if (Utils.IsNullOrWhiteSpace(path))\n            return false;\n\n\n         var drive = GetDirectoryRootCore(transaction, path, Path.IsPathRooted(path) ? PathFormat.FullPath : PathFormat.RelativePath);\n\n         var driveExists = null != drive && File.ExistsCore(transaction, true, drive, PathFormat.FullPath);\n\n         var regularPath = Path.GetCleanExceptionPath(path);\n\n\n         if (!driveExists && throwIfDriveNotExists || lastError == Win32Errors.ERROR_NOT_READY)\n            throw new DeviceNotReadyException(drive, true);\n\n\n         throwIfFolderOrFileNotExists = throwIfFolderOrFileNotExists && lastError != Win32Errors.NO_ERROR;\n\n         if (throwIfFolderOrFileNotExists)\n         {\n            if (lastError != Win32Errors.NO_ERROR)\n            {\n               if (lastError == Win32Errors.ERROR_PATH_NOT_FOUND)\n                  throw new DirectoryNotFoundException(regularPath);\n\n\n               if (lastError == Win32Errors.ERROR_FILE_NOT_FOUND)\n               {\n                  if (isFolder)\n                     throw new DirectoryNotFoundException(regularPath);\n\n                  throw new FileNotFoundException(regularPath);","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory.ExistsDrive.cs#L58-L94","documentation":"DeviceNotReadyException raised by ExistsDriveOrFolderOrFile when the drive backing the path exists but the OS reports ERROR_NOT_READY (21), i.e. the device has no media or is not initialized. AlphaFS throws this so callers explicitly learn a drive letter exists yet is unusable, rather than getting a false 'not exists' result.","triggerScenarios":"Directory.ExistsDrive(path) where File.ExistsCore confirms the drive root exists but lastError == Win32Errors.ERROR_NOT_READY — typically accessing an empty CD/DVD drive, an unmounted/sleeping removable drive, a disconnected network drive, or an offline VHD.","commonSituations":"Inventory/audit tools (like winPEAS) scanning all drive letters and hitting a card reader slot with no card, a USB stick that was yanked mid-session, or a mapped network drive whose host is unreachable.","solutions":["Physically/media-remediate the device: insert media, re-seat or reconnect the drive, restore the network share.","Retry after a short delay for transient unready states (spinning-up USB drives, reconnecting shares).","Wrap the existence check in try/catch for DeviceNotReadyException and treat the drive as 'unavailable' instead of failing the scan.","Filter out known unready letters before probing (e.g. check logical drive type/media via DriveInfo.IsReady)."],"exampleFix":"// before\nbool exists = Directory.ExistsDrive(driveRoot);\n// after\nbool exists;\ntry { exists = Directory.ExistsDrive(driveRoot); }\ncatch (DeviceNotReadyException) { Log.Warn($\"{driveRoot} not ready\"); exists = false; }","handlingStrategy":"try-catch","validationCode":"var di = new DriveInfo(Path.GetPathRoot(path) ?? \"\");\nif (!di.IsReady) { Log.Warn(drive + \" not ready\"); return; }","typeGuard":"static bool IsDriveReady(string path) { var root = Path.GetPathRoot(path); return root != null && new DriveInfo(root).IsReady; }","tryCatchPattern":"try { exists = Directory.ExistsDrive(path); } catch (DeviceNotReadyException ex) { Log.Warn($\"Device not ready: {ex.Message}\"); exists = false; }","preventionTips":["Check DriveInfo.IsReady before probing drive-backed paths.","Skip known-empty media slots (card readers, optical drives) in scan loops.","Retry once with a delay for slow-spinning removable media."],"tags":["csharp","windows","device-not-ready","drives","alphafs"],"backgroundTag":"device-not-ready","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}