peass-ng/PEASS-ng · warning · DeviceNotReadyException
ERROR_NOT_READY
ERROR_NOT_READY
Error message
({21}) The device is not ready: [{drive}] What it means
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.
Source
Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/Directory Class/Directory.ExistsDrive.cs:76
/// <summary>[AlphaFS] Checks if specified <paramref name="path"/> is a local- or network drive.</summary>
/// <returns><c>true</c> if the drive exists, <c>false</c> otherwise.</returns>
internal static bool ExistsDriveOrFolderOrFile(KernelTransaction transaction, string path, bool isFolder, int lastError, bool throwIfDriveNotExists, bool throwIfFolderOrFileNotExists)
{
if (Utils.IsNullOrWhiteSpace(path))
return false;
var drive = GetDirectoryRootCore(transaction, path, Path.IsPathRooted(path) ? PathFormat.FullPath : PathFormat.RelativePath);
var driveExists = null != drive && File.ExistsCore(transaction, true, drive, PathFormat.FullPath);
var regularPath = Path.GetCleanExceptionPath(path);
if (!driveExists && throwIfDriveNotExists || lastError == Win32Errors.ERROR_NOT_READY)
throw new DeviceNotReadyException(drive, true);
throwIfFolderOrFileNotExists = throwIfFolderOrFileNotExists && lastError != Win32Errors.NO_ERROR;
if (throwIfFolderOrFileNotExists)
{
if (lastError != Win32Errors.NO_ERROR)
{
if (lastError == Win32Errors.ERROR_PATH_NOT_FOUND)
throw new DirectoryNotFoundException(regularPath);
if (lastError == Win32Errors.ERROR_FILE_NOT_FOUND)
{
if (isFolder)
throw new DirectoryNotFoundException(regularPath);
throw new FileNotFoundException(regularPath);View on GitHub (pinned to 53fb989abc)
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).
Example fix
// before
bool exists = Directory.ExistsDrive(driveRoot);
// after
bool exists;
try { exists = Directory.ExistsDrive(driveRoot); }
catch (DeviceNotReadyException) { Log.Warn($"{driveRoot} not ready"); exists = false; } Defensive patterns
Strategy: try-catch
Validate before calling
var di = new DriveInfo(Path.GetPathRoot(path) ?? "");
if (!di.IsReady) { Log.Warn(drive + " not ready"); return; } Type guard
static bool IsDriveReady(string path) { var root = Path.GetPathRoot(path); return root != null && new DriveInfo(root).IsReady; } Try / catch
try { exists = Directory.ExistsDrive(path); } catch (DeviceNotReadyException ex) { Log.Warn($"Device not ready: {ex.Message}"); exists = false; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- drivePath
- Resources.InvalidDriveLetterArgument
- driveName
- Resources.InvalidDriveLetterArgument
- Resources.No_Drive_Letters_Available
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/f5276e9c11ebf770.
Report an issue: GitHub.