Referencing the example and info from Microsoft https://msdn.microsoft.com/en-us/library/system.io.driveinfo.getdrives(v=vs.110).aspx, I found the below code to produce the drive letter and type of all drives including those not currently connected but allocated.
using System;
using System.IO;
namespace DriveInfoExample
{
class Program
{
static void Main(string[] args)
{
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo d in drives)
{
// The only two properties that can be accessed for all drives
// whether they are online or not (ready)
//
Console.WriteLine(d.Name);
Console.WriteLine(d.DriveType);
}
Console.ReadLine();
}
}
}
Per the instructions on the link above, if you try to get other attributes on a drive the is not ready, an IOException will be thrown.
One way to handle this is to check drive.IsReady
for true with an if statement before getting the other properties (as shown below and almost directly ripped from the link above):
using System;
using System.IO;
class DriveInfoExample
{
public static void Main()
{
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo d in drives)
{
Console.WriteLine(d.Name);
Console.WriteLine(d.DriveType);
if (d.IsReady == true)
{
Console.WriteLine(d.VolumeLabel);
Console.WriteLine(d.DriveFormat);
Console.WriteLine(d.AvailableFreeSpace);
Console.WriteLine(d.TotalFreeSpace);
Console.WriteLine(d.TotalSize);
}
}
Console.ReadLine();
}
}
The key in the above example is the if (d.IsReady == true)
as it will only get attributes for drives that are considered ready and you wont throw an IO Exception.