Пример #1
0
        public static void UnlockBasicDiskAndVolumes(PhysicalDisk disk)
        {
            List <Partition> partitions = BasicDiskHelper.GetPartitions(disk);

            foreach (Partition partition in partitions)
            {
                Guid?windowsVolumeGuid = WindowsVolumeHelper.GetWindowsVolumeGuid(partition);
                if (windowsVolumeGuid.HasValue)
                {
                    WindowsVolumeManager.ReleaseLock(windowsVolumeGuid.Value);
                }
            }

            disk.ReleaseLock();
        }
Пример #2
0
        public static DynamicDisk FindDisk(Guid diskGuid)
        {
            List <int> diskIndexList = PhysicalDiskUtils.GetPhysicalDiskIndexList();

            foreach (int diskIndex in diskIndexList)
            {
                PhysicalDisk disk;
                try
                {
                    disk = new PhysicalDisk(diskIndex); // will throw an exception if disk is not valid
                }
                catch (DriveNotFoundException)
                {
                    // The disk must have been removed from the system
                    continue;
                }
                catch (DeviceNotReadyException)
                {
                    continue;
                }
                catch (SharingViolationException) // skip this disk, it's probably being used
                {
                    continue;
                }

                DynamicDisk dynamicDisk = DynamicDisk.ReadFromDisk(disk);
                if (dynamicDisk != null)
                {
                    if (dynamicDisk.DiskGuid == diskGuid)
                    {
                        return(dynamicDisk);
                    }
                }
            }
            return(null);
        }