/// <summary> /// <para>Creates a new <see cref="StorageDisk"/> from the specified <paramref name="UnitMask"/></para> /// </summary> /// <param name="UnitMask"></param> /// <returns></returns> internal static StorageDisk FromUnitMask(int UnitMask) { if (UnitMask == 0) { return(new StorageDisk(null, null, null)); } char Letter = FirstDriveFromMask(UnitMask); StorageDisk sd = null; ManagementObjectCollection partitions = new ManagementObjectSearcher(String.Format("ASSOCIATORS OF {{Win32_LogicalDisk.DeviceID='{0}:'}} WHERE AssocClass = Win32_LogicalDiskToPartition", Letter)).Get(); foreach (ManagementObject partition in partitions) { ManagementObjectCollection disks = new ManagementObjectSearcher(String.Format("ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{0}'}} WHERE AssocClass = Win32_DiskDriveToDiskPartition", partition["DeviceID"])).Get(); foreach (ManagementObject disk in disks) { sd = CreateStorageDiskFromDrive(disk); break; } } if (sd == null) { ManagementObjectCollection cdroms = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_CdRomDrive WHERE Drive = '{0}:\'", Letter)).Get(); foreach (ManagementObject cdrom in cdroms) { sd = new CdRomDrive(cdrom); break; } } ManagementObjectCollection volumes = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = '{0}:'", Letter)).Get(); foreach (ManagementObject volume in volumes) { sd.AddPartition(new Partition(volume)); break; } return(sd); }
/// <summary> /// <para>Creates a new <see cref="StorageDisk"/> from the specified <paramref name="UnitMask"/></para> /// </summary> /// <param name="UnitMask"></param> /// <returns></returns> internal static StorageDisk FromUnitMask(int UnitMask) { if (UnitMask == 0) return new StorageDisk(null, null, null); char Letter = FirstDriveFromMask(UnitMask); StorageDisk sd = null; ManagementObjectCollection partitions = new ManagementObjectSearcher(String.Format("ASSOCIATORS OF {{Win32_LogicalDisk.DeviceID='{0}:'}} WHERE AssocClass = Win32_LogicalDiskToPartition", Letter)).Get(); foreach (ManagementObject partition in partitions) { ManagementObjectCollection disks = new ManagementObjectSearcher(String.Format("ASSOCIATORS OF {{Win32_DiskPartition.DeviceID='{0}'}} WHERE AssocClass = Win32_DiskDriveToDiskPartition", partition["DeviceID"])).Get(); foreach (ManagementObject disk in disks) { sd = CreateStorageDiskFromDrive(disk); break; } } if (sd == null) { ManagementObjectCollection cdroms = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_CdRomDrive WHERE Drive = '{0}:\'", Letter)).Get(); foreach (ManagementObject cdrom in cdroms) { sd = new CdRomDrive(cdrom); break; } } ManagementObjectCollection volumes = new ManagementObjectSearcher(String.Format("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = '{0}:'", Letter)).Get(); foreach (ManagementObject volume in volumes) { sd.AddPartition(new Partition(volume)); break; } return sd; }