peass-ng/PEASS-ng · error · ArgumentOutOfRangeException

Resources.No_Drive_Letters_Available

Error message

Resources.No_Drive_Letters_Available

What it means

AlphaFS GetFreeDriveLetter collects available drive letters and throws ArgumentOutOfRangeException(Resources.No_Drive_Letters_Available) inside a catch when the candidate list is empty (First()/Last() on an empty sequence). It means the system has no unoccupied drive letters (A-Z all in use).

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Device/DriveInfo.cs:311


      /// <summary>Gets an available drive letter on the local system.</summary>
      /// <param name="getLastAvailable">When <c>true</c> get the last available drive letter. When <c>false</c> gets the first available drive letter.</param>
      /// <returns>A drive letter as <see cref="char"/>. When no drive letters are available, an exception is thrown.</returns>
      /// <remarks>The letters "A" and "B" are reserved for floppy drives and will never be returned by this function.</remarks>
      /// <exception cref="ArgumentOutOfRangeException">No drive letters available.</exception>
      [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
      public static char GetFreeDriveLetter(bool getLastAvailable)
      {
         var freeDriveLetters = "CDEFGHIJKLMNOPQRSTUVWXYZ".Except(Directory.EnumerateLogicalDrivesCore(false, false).Select(d => d.Name[0]));

         try
         {
            return getLastAvailable ? freeDriveLetters.Last() : freeDriveLetters.First();
         }
         catch
         {
            throw new ArgumentOutOfRangeException(Resources.No_Drive_Letters_Available);
         }
      }

      #endregion // Methods


      #region Private Methods

      /// <summary>Retrieves information about the file system and volume associated with the specified root file or directorystream.</summary>
      [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
      [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
      [SecurityCritical]
      private object GetDeviceInfo(int type, int mode)
      {
         try
         {
            switch (type)
            {

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Free a drive letter: disconnect unused mapped drives ('net use * /delete' selectively) or remove subst mappings
  2. Check occupied letters with 'net use' / Get-PSDrive and clean up stale mappings before retrying
  3. Enumerate existing letters yourself and fail gracefully with a clear message instead of calling GetFreeDriveLetter
  4. Reduce automatic mountpoints (VHDs, network shares) or use UNC paths instead of drive letters

Example fix

// before
var letter = DriveInfo.GetFreeDriveLetter(); // throws when full
// after
var used = System.IO.DriveInfo.GetDrives().Select(d => d.Name[0]).ToHashSet();
var free = Enumerable.Range('A', 26).Select(c => (char)c).Where(c => !used.Contains(c)).ToList();
if (!free.Any()) throw new InvalidOperationException("No free drive letters; disconnect unused drives.");
var letter = free[0];
Defensive patterns

Strategy: try-catch

Validate before calling

var used = System.IO.DriveInfo.GetDrives().Select(d => d.Name[0]).ToHashSet();
bool hasFree = Enumerable.Range('A', 26).Any(c => !used.Contains((char)c));
if (!hasFree) throw new InvalidOperationException("All drive letters are in use.");

Try / catch

try
{
    var letter = AlphaFS.Device.DriveInfo.GetFreeDriveLetter();
}
catch (ArgumentOutOfRangeException)
{
    // all 26 letters used: free one up or fail gracefully
    Console.Error.WriteLine("No free drive letters; disconnect unused drives.");
}

Prevention

When it happens

Trigger: Calling GetFreeDriveLetter() (or GetFreeDriveLetter(true)) when every drive letter A–Z is already mapped/occupied, so freeDriveLetters is empty and First()/Last() throws.

Common situations: Machines with many mapped network drives, mounted VHDs, and subst drives exhausting all 26 letters; container/imaging systems that map everything; repeated drive mounting without cleanup.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/96e4cca90e33469e. Report an issue: GitHub.