public SearchDisksForm(MainForm main) { this.main = main; InitializeComponent(); DriveInfo[] drives = DriveInfo.GetDrives(); CheckedListBox checkedBox = disksBox; for (int i = 0; i < drives.Length; i++) { DriveInfo drive = drives[i]; SearchDriveInfo d = new SearchDriveInfo(); d.drive = drive; if (drive.IsReady) { if (drive.DriveFormat != "NTFS") { // ignore non-NTFS drives continue; } try { long free = drive.AvailableFreeSpace / 1024 / 1024 / 1024; long total = drive.TotalSize / 1024 / 1024 / 1024; long used = total - free; d.text = drive.Name + " " + used + " GB used"; checkedBox.Items.Add(d, true); } catch { // notify user of crash d.text = drive.Name + " (Not authorized)"; checkedBox.Items.Add(d, CheckState.Indeterminate); } } else { // user might want to get that drive ready d.text = drive.Name + " (Drive not ready)"; checkedBox.Items.Add(d, CheckState.Indeterminate); } } }